Rotating a fire sprite to face the opposite direction of where a ball sprite is headed.

Hi guys, I’m currently working on a school assignment where I need to ‘pimp out’ breakout. The game is using 3D physics with 2D sprites in an orthographic view. As such, all the main rotation for the ball is on the z-axis and the ball moves upwards on the y-axis and side to side on the x-axis. I currently have a ball, and as a child of the ball I have an animation of a flame, giving the ball the appearance that it’s on fire. I also have a trail renderer attached to the ball to give it the appearance of a flame trail being left behind it. My question is, is there a way to rotate the fire so that it either:

A. Goes opposite the direction the ball is moving, so it appears that it’s being affected by ‘wind’
B. The tip of the fire always stays at the start of the trail renderer, which is already following the ball how I would like the fire to.

I’ve attached an image of what I’d LIKE the fire to do (set it up during a paused test).

C# preferred!

Thanks guys :slight_smile:

Well, they are both possible for sure. A) should be fairly easy, but I imagine B) would be, well, a bit more complex and definitely more work. (You’d need to know for each frame of your animation where the relative position of the fire’s tip is, then when it’s being played keep track of what frame your animation is currently in, and then move your animation s.t. the tip is at the start of the trailrenderer.) So I don’t know if you want to do that. What you should probably do is just have the trailrenderer start somewhere inside the fire and be sure you draw the fire animation on top of the trail. (It will probably look better anyway than have your animation move around - that will probably just look like it’s lagging).

As for rotating the fire animation gameobject. I’ll assume the ball itself doesn’t actually rotate. First you’ll need to find out the direction your ball is moving in in the xy-plane. So that gives you a Vector2, and now you could do some manner of trigonometry stuff to calculate the correct angle etc. But, instead, take the easy way: Get a Vector3 instead of a Vector2 for your move direction. We’ll call this the ‘look direction’ vector. (Make sure that the z-look direction is 0.). Then use Quaternion.LookRotation(lookdirection) to translate that into a rotation quaternion. Then set the rotation of your animation gameobject to that quaternion. There, done! No, wait, we want the animation to be in the direction opposite of the direction we’re moving in. So just invert the look direction before we turn it into a quaternion. Done, no trigonometry needed.

I hope this helps you. (Not giving exact code since it’s a school assignment…you should be able to work it out from here though.)