Add or subtract animation frames when object rotates

I have an object plantturret that rotates 22.5 degree increments depending on the players position and an object plant with frames of animation that correspond to the rotation of plantturret but I can’t work out the syntax to make the animation frames of plant go forward or backward when plantuttet rotates? for example when rotation increases 22.5 degrees clockwise add 1 frame when decreases anticlockwise subtract a frame each time.

plantturret rotation

What is the range of the frames? Does it go from 0 to 360?

9 frames a frame for each angle increment to half rotation

I’d look at using something along the lines of

plantturret.animation = trunc((plantturret.angle + 11.25)/22.5)

I don’t understand how to add that into the events? the plant has an animation with 9 frames and plantturret rotates no animation. when the planturret rotates in increments of 22.5 degrees the plant object should go to the next frame each increment.

Ah, it was late at night when I did this, and put in the wrong object. Where you set plant animation number *last event of the screen snip), use :

Change the animation frame of plant = trunc((plantturret.angle + 11.25)/22.5)

thanks for your reply I tried adding as a condition but nothing happens what am I doing wrong?

events

It’s an action, not a condition. Instead of setting the animation to 1, set it to the formula in my previous message :

That event should have no condition.

nothing happens and I don’t know why?

events

platturret.angle is incorrect. It should be plantturret.Angle() - it’s case sensitive and rounded brackets required as it’s a function.

1 Like

ok I see now this works but the animation is opposite direction to plantturret thanks for your help I didn’t know the syntax I will try to work out the directions

Then either reverse your animation frames, or use the algorithm 8 - trunc((plantturret.angle + 11.25)/22.5).

thanks for your help I’m really stuck and can’t get the animation to align with the rotation. I have uploaded json file you can see what I’m trying to do but the animation is off possibly has to do with the rotation being 270 degrees? plant animation uses 7 frames half the radius then flip plant for the opposite half?

green is the radius of rotation
Sprite-0001

json file

I’ve had a look at you project. For the plant animation, you’ve got the same image for each frame, just rotated around a bit. If that’s all you’re doing with the image, why not just use the plantturret’s rotation and have only one frame for the plant’s animation?

I’m working on a solution. Bear with me (if someone else doesn’t manage to work it out before me). It’s a tad tricky because the angles go from 45 to -180, and then from 180 to 135 and the change isn’t in the middle of the rotation.

1 Like

can anyone help me with a simple way to get frame with rotation to work I’m still stuck :frowning:

Sorry, I’ve been on holiday and kept this on the backburner. Here’s my solution :

Effectively it gives each angle a frame number - 0 for right and down, to 12 for left and down, in an anticlockwise direction.

1 Like

thanks very much works perfect! I really wish I knew the syntax I never would have got it. sorry to bug you about it thanks for your help.

1 Like

I’m now having a problem when adding multiple instances of plantturret and plant because plantturret is at different positions to the player but plant frames are set to the initial plantturret. I tired for each object and also changing the scene variable to object variable but that didn’t work :confused:

problem with multiple instances
animation

Needs to be both a “for each” AND use object variables, rather than scene variables.

You’ll need to move some stuff around to accommodate that.