#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Restrictions of constraining animation to velocity with max speed

Posts: 450Member

Hey guys, I'm currently using accelerate to control movement as I like the way the speed gradually increases, rather than instantly going to full speed.

I also use a constrain image to the actors magnitude so actor's animation speed matches the actor speed:
constrain self.image to "walk_"..floor((magnitude( game.hero_x_speed , game.hero_y_speed )/30%8)+1)

This works great. HOWEVER, the downside of accelerate is that on long uninterrupted stretches the actor's speed gets too fast. But applying a max speed means that the animation method breaks, as at top speed, the image is constrained to just one frame.

Does anyone have any other solutions to making animations align to an actor's speed, using accelerate but with a max speed?

• Posts: 2,769Member, Sous Chef, PRO

Perhaps you can replace x and y speed attributes with:
self.Motion.Linear Velocity.X
self.Motion.Linear Velocity.Y

• Posts: 450Member

@RThurman said:
Perhaps you can replace x and y speed attributes with:
self.Motion.Linear Velocity.X
self.Motion.Linear Velocity.Y

Sorry, should have mentioned, those attributes are constrained to the x and y velocity.

(only reason I'm not using them directly as I have a combination of master and slave actors, master controlling the physics and collides, the other actor just following on top and playing the right animation. It's a hang over from before we had custom collisions and I haven't broken the habit.)

• London, UK.Posts: 12,832Member
edited June 2017

@imjustmike said:
Does anyone have any other solutions to making animations align to an actor's speed, using accelerate but with a max speed?

Constrain a controller actor's angular velocity to the original actor's speed, then constrain the animation frame to the controller actor's angular velocity.

• Posts: 2,769Member, Sous Chef, PRO

How about making animation frame a function of the x-coordinate?

• London, UK.Posts: 12,832Member

@RThurman said:
How about making animation frame a function of the x-coordinate?

Good idea (assuming the actor is only moving horizontally), this is probably the most straightforward trouble-free method.

• Posts: 450Member

@Socks said:

@RThurman said:
How about making animation frame a function of the x-coordinate?

Good idea (assuming the actor is only moving horizontally), this is probably the most straightforward trouble-free method.

Unfortunately the actor has a jump animation for movement along the y axis!

• Posts: 2,769Member, Sous Chef, PRO

You can handle the jump animation separately from straight horizontal movement.

Are you concerned about the transition between jump and horizontal animations? Wouldn't you have the same concerns with your current setup?

• Posts: 450Member

@RThurman said:
You can handle the jump animation separately from straight horizontal movement.

Are you concerned about the transition between jump and horizontal animations? Wouldn't you have the same concerns with your current setup?

I am handling it separately. I'm not concerned about the jump frame rate as it's fixed.

I guess I could apply an additional rule that says if moving AND NOT jumping, use this animate behaviour, elseif moving and jumping, do this. I'm now pretty sure that's actually what you were talking about! I'll have a play tomorrow when I'm a bit more awake.

Sorry, I'm pretty sure it took me reading this three times for the simple point to sink in and for me to understand what you mean!

• London, UK.Posts: 12,832Member
edited June 2017

@imjustmike said:
I guess I could . . .

Your issue is that an increasing value increases up until a certain point and then holds at that value. Which is no good for you as your animation relies on that value changing.

You instead want that value to increase up until a certain point and then stop increasing, but continue to return a changing value.

This can be done by rotating an actor faster and faster, when you reach a certain speed of rotation, you can stop increasing the speed - and the actor will continue to rotate at that speed, returning a changing value.

That's why I suggested you use a rotating controller to control the animation frame, it's a super simple, super flexible way to control animations.

Example file attached:

• Posts: 9,901Member

You could also have a series of animations just for that max speed. When max speed is reached the animation kicks in and cuts out the adjustable animation. When speed drops the main animation takes over.

• Posts: 2,769Member, Sous Chef, PRO

That's a great idea!

• Posts: 450Member

@Socks said:

@imjustmike said:

That's why I suggested you use a rotating controller to control the animation frame, it's a super simple, super flexible way to control animations.

Example file attached:

This is super useful, thanks so much. I also found a post you made detailing this method from a little while ago which helped me play around with frame rate etc.

I also tweaked the rotating actor (setting a max angular velocity lower than the x velocity) and add a bit to the actual value as I found that the animations were starting a little too slowly, then going too quickly. A combination of an increased started angular velocity and a max cap resulted in EXACTLY the effect I was looking for. THANKS!

• Posts: 450Member
edited June 2017

You could also have a series of animations just for that max speed. When max speed is reached the animation kicks in and cuts out the adjustable animation. When speed drops the main animation takes over.

I managed to get @sock's method working great, but I like the simplicity of this solution - I plan on using this on enemies where getting the animations exactly right isn't as crucial. THANKS. Two solutions used in two different places. Amazing

• London, UK.Posts: 12,832Member
edited June 2017

@imjustmike said:
This is super useful, thanks so much . . .

It's a good approach because all the things people want from an animation suddenly become very straightforward to do . . . want the animation to play backwards, simple, just rotate the controller backwards, want the animation to slow down to a stop then stick a bit of angular drag on the controller, want the animation to loop backwards then forwards then backwards (and so on repeating) then constrain the controller to a sine wave, want the animation to pause and then later continue from the exact frame it paused on (a very common request) then just throw a rule onto the controller that stops the rotation and then continues the rotation . . . (etc etc) . . . you basically simplify the playing of an animation to the rotating of an actor, and in GameSalad there are numerous easy to control ways of playing around with the rotation of an actor . . . want to play your animation at 60fps (GameSalad's default animation behaviour won't go any faster than 30fps) ? Easy, just rotate the controller actor at 60°/sec ! . . . Things which are quite difficult / involved to do if you are dealing directly with an animation behaviour or direct constrain (constrain self.image to . . . . ) become really easy to implement, change, control and understand when the animation frame is simply the angle of a separate controller actor.

• Posts: 450Member

@socks ability to control the framework is insanely useful. I'm looking forward to playing around with some of the other functionality, being able to loop back and forth with a few frames can be used in so many different ways

• Posts: 2,769Member, Sous Chef, PRO
edited June 2017

@Socks said:

That's why I suggested you use a rotating controller to control the animation frame, it's a super simple, super flexible way to control animations.

Example file attached:

Thats a really nice way of controlling the animation!
Does it have to be angular velocity of the controller? Can't you also do the same thing with x (or y) velocity? (I guess you would have to make the controller actor wrap back to 0 whenever it reaches 360.)