Download

Problem With Radial Impulse

problem1.png

I added a radial impulse to my sphere blueprint (ball) so that when my player left clicks it would kick the ball but it doesn’t seem to be working. When I approach the ball the ball moves when my character collides with it but when I left click nothing happens. It is simulating physics.

Check “Velocity Change”.
Radial impulse without it works kind of like add force, to see effect you would do it with on tick event.
Also check mass of ball. To test if physics works at all move it above ground and enable gravity, if it falls down it is active and physics works.

Also Origin location looks suspicious. Radius of player character collision is 42 units, origin of standard player is 90 units above ground, you add 100 more. This resulting angle is quite steep (75degrees ).
Then you have radius of 200, that may be outside of range. Well its 194.6 so about at max.
And last 500000 is quite big strength.

Ps one more thing, add some printing to this graph so you cansee that event for mouse actually happened, not all blueprints recive input.

Hey Nawrot, thanks for replying so quickly!

So I did what you said and checked “Velocity Change” and added “Event Tick” instead of the mouse click and every time my player approaches the ball the ball would fly away, which is exactly what I wanted. It also works without checking “Velocity Change”. It seems like the reason it doesn’t work is because it’s not taking in any inputs since I tried a variety of keys and it’s still not working, any idea how to fix that?

I am quite new to Unreal Engine, is there documentation on the units and angles calculation? I just simply followed someone else’s tutorial.

Lastly, when you say add some printing do you mean turn on the nodes firing? Because I’ve been trying to get that back for a while now since it’s so useful for debugging but I can’t seem to find the reason why it’s turned off.

I seem to have fixed the input issue by going into the class defaults and added input from player 0. Just curious, if the game has more than 1 player and I want all the players to be able to kick the ball, how would I do that?

Only pawn and player controller can get input.
You just forced that input, it will work but this is not best way to handle that.

Handle that input event in playercontroller.
When you press key you get event there, from that event search for all blueprints that are “BALL” (get all actors of class)
If you have just one ball, get value at index 0 (get node dragged from blue array pin)
And now you should have reference to your ball blueprint, create node cast to “ball”

Now create function inside ball that does radial impulse (exactly what you have now for keyboard event)

And finally call that function from playercontroller.

also search for tutorials about blueprint communication.

Hey Nawrot, thanks for the reply again! Your solutions and advice are very helpful! I was actually looking for tutorials on blueprint communication but I wasn’t sure what to search up!

Just another quick question (sorry), is there a way to add a direction to an impulse? For example if I get a character to “kick” the ball and I want the ball to go the location where my cursor is, independent of the direction that the character is facing, how would I approach that?

Thanks again!

If you want more control ove where to kick, you need to drop radial impulse.
But first make all with radial impulse working. Then improve it.

When you have all working with radial impulse. You should have center of radial impulse, and location of your ball.
At that point you really do not need radial impulse anymore, you can use simple “add impulse”
So you have place of ball, and place of target, calculate direction vector for them (destination location - start location), then NORMALIZE that vector (it makes it length 1).
Now add impulse to that ball and vector should be Normalized direction * strength. I do not remember if add impulse takes vector and strength separately, if so feed normalized and strength to their pins instead.

You probably want to make spinning ball kicks (do not know how this thing is called in english). And this is bit more complicated.
For it to work you need add some functionality to the ball. Ie add there variable that holds direction vector, and force.
When you kick ball calculate vector “left” or “right” vector to direction you are kicking ball. For this rotate (by 90deg) around axis [0,0,1] your normalized vector from above paragraph. There is also simpler method, instead of valculating that vector as right vector use “get physics velocity”, and rotate that. This will be more accurate, but also may introduce strange drifting because you constantly will update direction. This is place where you just experiment with physics see what is best for your game.
Then store it in ball (so it knows how to curve), somehow calculate strength (or amount) of curving.
Then on event tick in ball you need to “add force” that will drag ball slowly to the side.

If you want more advanced simulation you need to dig quite deep into physics, to calculate that stuff over time, check spin speed etc.
I am not sure if you can read direction that physics body is spinning, if its possible, you could find drag vector from spinning ball, then apply that as “add force”

Hey Nawrot, your advice has once again been very helpful! I followed what you said and added a vector and that worked well! As for the spin I think it might be too complicated for someone who is just starting out like me, but I’ll definitely save what you said in a notepad so when I revisit it I can try to implement it.

As you might have guessed I am working on a football (soccer) game. I currently have a pickup system set up so the player picks the ball up when he is near but I am also having some problems with that. I don’t want to bother you too much but your help would definitely be great. Is it okay if I show you the problem in a message? As this is not related to the topic of this post.

Once again, many thanks for your help!

Do not do private messages for problems like this, it is better to have it all in topic. Others in a year or so may find this helpful, mind all newbies that come after you.
Some of my posts from UT3 from 2007 are still valid, so better is to keep that stuff public.

Ps. Continue here, its nice to have all that stuff in one topic. And happy new year!

Happy new years to you too!

So I’ve been using this tutorial for my pickups: https://www.youtube.com/watch?v=E1xspC8UtZs
which is summarized in: https://wiki.unrealengine.com/Pick_Up_Physics_Object_Tutorial

I’ve been having problems where if my character approaches the ball really fast or if he turns suddenly the ball would fly off. I think the problem is since my character is in a top down view, the approach and transition between directions is too sudden and that causes the ball to fly off. What do you think would be a fix for this?

Thanks in advance!

Weird stuff with physics collision i say. First try to fix collision, but i doubt it will work.

Because the ball is just one actor and its quite important to your game you can give it some real processing power. So there is nothing wrong with doing some checks in event tick for ball.

You can counter this problem by tracing state of ball and changing its maximum velocity, or if that is possible its collision (i never tried this so i am guessing). So when ball stopped and does not move you can increase its mass until player is close. However i think this solution is kind of kicking contest with horse.

So instead:

I think best solution for you is if you make ball never collide with player pawn (that can be set in collision properties), and if ball ignores player you will not have those weird fly offs.
But if you do this you need to trace ball location relative to player and apply forces to ball that fake collision.
For that you can set player to overlap ball instead of collision and use"on overlap" event to handle player and ball collision. From that you will have locations of ball, overlap location etc.
Yes simulating football game is not easy task.

I think this is much better solution as you will have great control over collision with ball.

Hey Nawrot, thanks for the tip! It seemed to fix the issue a bit as it doesn’t fly off immediately on touch but if I try hard enough turning rapidly it would still fly off.

Also I shouldn’t turn off all the collision for the ball right? Because when I turn it off it seems that the ball can’t be picked up.

Yeah, only turn off what you need so it doesn’t actually hit your player pawn (check the pawn’s “object type” in it’s collision settings). You don’t want to turn off visibility, camera, worldstatic, stuff like that. (unless you’re going to turn it on again after it’s kicked.) Though it depends on how your “picking up” stuff works, you should probably check that to make sure it will work together with your kicking setup.

Hey Ross, thanks for the heads up. My pickup uses a line trace and “grab component” so whenever my line trace hits the ball, which is a physics object, it picks the ball up. My kicking works fine but whenever I try turning quickly the ball just disappears and it looks like it flew off really quickly.