Changing rotation during actor movement, Math?
jjonasz
Member Posts: 7
Hi everyone, I wanted to say that these forums are super helpful and I've learned a lot about GS from all you guys!
I am making a game and have a question about creating a smooth movement for an actor.
I have an attribute for the distance that the character is to move during the movement phase of my game as well as an attribute for the angle that the actor is to rotate during the movement. I can't figure out a good formula or rule for making it a smooth movement where the rotation happens throughout the movement, so that when the actor is moving to it's destination (as per the distance attribute) it is turning to finally face the angle set by the angle attribute.
ie: I don't want the actor to rotate and then move, I would like it to spread the full rotation over the move.
Any suggestions?
-JJ
I am making a game and have a question about creating a smooth movement for an actor.
I have an attribute for the distance that the character is to move during the movement phase of my game as well as an attribute for the angle that the actor is to rotate during the movement. I can't figure out a good formula or rule for making it a smooth movement where the rotation happens throughout the movement, so that when the actor is moving to it's destination (as per the distance attribute) it is turning to finally face the angle set by the angle attribute.
ie: I don't want the actor to rotate and then move, I would like it to spread the full rotation over the move.
Any suggestions?
-JJ
Comments
constrain self.rotation to vectorToAngle(self.linear.motion.X,self.linear.motion.Y)
I would check out one of GameSalad's demos. Open up GameSalad Creator, choose the "New" tab on the left. Open the Cannon Physics project, and then open the Ball actor and see how it rotates. If you preview the project, you will notice that the ball rotates very smoothly. Hope this helps.
Thanks for the quick suggestions!!
I took a look at the ball demo, but it's not quite what I'm trying to do. I've been trying out the rotate to angle and position behaviors but the problem is that the actor rotates but the direction it is moving in does not change.
I don't think I explained it well. Basically my actor is a boat that needs to travel in a known direction (angle of travel) with a known distance it will go. The boat should always be facing forward but the direction of it's movement should be changing so that it gets ends up facing the angle that was selected at the beginning and crosses the distance that was set, all while travelling the way a boat would.
When I use Rotate to angle or rotate to position, the direction the boat is facing changes, not it's direction of travel as both Move To rule and Rotate rule happen at the same time. So I cover the right distance but I have a boat that slides sideways
-JJ
http://gamesalad.com/game/2928
I'm going to try just using the regular Move behavior and slowly change the angle of the move to simulate this.
Here's an example of what I'm trying to achieve:
My actor "Boat" is at coords 0, 0. I know that I want the boat to end up at an angle of 45degrees in 200 pixels. The boat should travel along an arc as it turns towards 45degrees. ie: it should end up at (i think) around 141,125, facing 45degrees.
There has to be some way simple way to do this, no?
http://www.resqwest.com/TEST/cos_angles_circles_demo.gameproj.zip
I don't know if it will help but it is the only demo I have seen where an actor takes a circular path. Additionally it shows the math involved and displays text that follows the path but doesn't rotate so I thought there might be something in it for you.
S