How to get reflectance rotation (ricochet)

I have a mesh that moves forward at a constant rate. I want it to hit a wall and ricochet off at the angle of reflectance. There are plenty of examples of doing this with a line trace but I can’t find any the explain how to directly affect a meshes’ rotation.

235437-reflect.png

This pic shows what I have, but it only works for walls on the X axis, not on Y or at odd angles. If anyone could tell me how to rotate my mesh correctly I’d be very grateful, thanks!

Hi,

I had to do the reflection mechanic recently, I just didn’t know about the node you are using. Well, it’s useful to know.

My suggestions:

  • normalize the vector, if you want to use it as a direction vector,
  • always be sure what your vectors mean, maybe you are doing something wrong with vector math. Visualizing the vectors with debug line traces is the best method to get every vector right. Also, check whether the “Find look at rotation” vector inputs are world or relative to your actor, I don’t remember.
  • you are using overlap, so the reflected body is going to be inside the tested obstacle. Thus, I’m not sure about the locations of impact from an event. Those might be good though, you need to test it.
  • I’m using line trace because when I used hit event, the hit location wasn’t the actual hit location the body was going for, concerning its velocity. The hit location was in fact a point of contact of the sphere I used for collision. So line trace is used and the start location is the centre of my collision sphere (actor location). The line trace is looking for hit location as the hit location didn’t happened yet.
  • As for rotation, you can rotate the whole actor or rotate only its mesh. It’s up to you. Rotating mesh is useful when you are doing other rotations with the whole actor, or depend on some calculations which needs static actor rotation.
  • The easiest way of rotating the actor towards a vector is to use nodes called “make rot from…”. For a long time I didn’t know what those nodes are for, because of their stupid name. But when you realize how they works, its a big confusing disappointment: “why didn’t I use those before? They fix all my problems!” Here is a video for you: UE4 Make Rot From X - YouTube
  • As for previous point: I’m changing the rotation towards velocity in every tick. You could do the same or rotate once when reflected, do as you like actually.
  • Be sure, the character is not using the controller’s rotation. If it is, rotations will overwrite each other.
  • I’m not sure if multiplying the rotator’s Z by -1 is a good idea. Instead, combine the rotators. Also, I think the node “Get Reflection Vector” already found a reflection vector, so you don’t need to modify it, simply use it as it is.

I hope I helped a little. Be sure to check the answer if you are satisfied with it!

// Taberu

Thanks Taberu! I’m still not 100% sure about some things but it’s a good opportunity to improve my understanding of vectors. I’ll give the “rot from” vid a watch and see how I get on. Thanks very much for the explanation.

I adapted your blueprint and got it working, thanks again!