Hi,
I have an actor which contains a sphere mesh. I’m hitting that actor with a line trace and then adding an impulse to move it. I want it to act like a ball, so for example hit it in the centre and it will go forward, hit it towards the bottom ( I.e. 6 o’clock on a clock face) it will go forwards and up etc.
To do this I tried to flip the impact normal from the line trace and multiply that by a float and then add it to the actors current location. I drew a line cast to represent this while testing and the line cast points in the location I want. However the actor is going in a different direction. For example if I face my character along negative Y and hit the ball in the centre the line cast is drawn in the same direction I’m facing but the ball moves to the left (I.e. negative X). If I try from the opposite side of the ball (I.e. character facing along Y) and hit the ball in the centre it still goes to negative X (I kind of expected it to do the opposite and go to positive X).
I’ve tried using Add Impulse and Add Impulse at Location. Here is the related section of my blueprint:
Example of what’s happening (I’ve drawn the axis in the background to make it clearer):
I shot it here:
And this is where it went vs where the line trace is showing I want it to go:
Despite the line trace going in the correct direction I’ve probably made a mistake with my vector maths, but I can’t figure out what I’m doing wrong. Any help would be appreciated.
What kind of collision does that ball have? A Sphere collision I hope, so that it doesn’t influence its movement when it’s rolling around (a “Sphere” collision is mathematically perfectly round, no edges or corners to drive it in a different direction).
Try using the “Normal” output pin instead of the “Impact Normal” from that Line Trace.
You’re getting the static mesh component and applying impulse to that instead of the whole thing? Seems a bit weird to add impulse to only a component… Try converting that ball into a blueprint and set the static mesh component as the root of that blueprint.
Lastly, make sure that green plane it’s rolling on is perfectly flat, because it looks tilted to the left in the screenshots (easiest way to test is to rotate it 180 degrees and see if it’s favouring the right side then).
Thank you for your reply.
The ball does have a sphere collision.
I’ve tried both Normal and Impact Normal (which both appear to be the same when using a Line Trace). I’ve now decided to impulse in the direction the camera is facing instead so I’m not using either and still have the same problem. My new calculation is: Hit Actor->Get Actor Location + (Camera->Get Forward Vector * 250).
I originally had the Sphere Collision as the root component but had an issue where the Sphere Collision and the Mesh would separate when the impulse was added and changed it as a test (I think I solved that by removing the Projectile Movement and using a Physics Material instead). I’ve now put the Sphere Collision back to the root.
The reason I’m applying the impulse to an individual component is because ‘Add Impulse’ requires a target type of ‘Primitive Component Object Reference’. I originally cast the Hit Actor to the ball’s blueprint but when I connect this to ‘Add Impulse’ it ‘converts’ the object by grabbing the Sphere Collision variable/component from the blueprint. I thought (maybe incorrectly) that Get Component by Class may have less performance impact than casting? Either way I have tried again by casting but it still ‘converts’ to the Sphere Collision and doesn’t solve the problem.
I have moved the player and ball back into the zone included in the first person template which appears to just use a basic cube object as the floor to make sure it’s flat, but I still have the same problem. Hitting the ball from one direction even pulls it towards me instead of pushing it away.
I figured out where I was going wrong. I was adding the hit actor’s location to the impulse I.e. Impulse = Hit Actor’s Location + (Flipped Impact Normal x Magnitude). All the impulse needs is the direction and magnitude I.e. Flipped Impact Normal x Magnitude.
I decided however that I want to apply the force in the direction the camera is facing rather than from the impact point towards the centre of the sphere. So I replaced the Impact Normal with the camera’s forward vector.
2 Likes