Changing rotation during actor movement, Math?

jjonaszjjonasz Member Posts: 7
edited November -1 in Working with GS (Mac)
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

Comments

  • scitunesscitunes Member, Sous Chef Posts: 4,047
    If you know exactly how long it will take to get to the end point use interpolate and set that time.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    Also if you want it to rotate so it is always facing forward even as it turns just use:

    constrain self.rotation to vectorToAngle(self.linear.motion.X,self.linear.motion.Y)
  • osucowboy18osucowboy18 Member Posts: 1,307
    Hey jjonasz,

    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.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    osucowboy18 said:
    Hey jjonasz,

    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.

    In that demo that just use a simple rotate rule, but that will not give you control over the stop point. You can also try rotate to angle or rotate to position.
  • jjonaszjjonasz Member Posts: 7
    Hey guys,

    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
  • simo103simo103 Member, PRO Posts: 1,331
    trying to help although my skill set is limited. I saw this demo and remembered you problem and thought there might be some code in it that might help. The actor follows the mouse in this example perhaps you can get it to follow a small one pixel by one pixel transparent actor that has travelled the exact route the boat will take only moments earlier?
  • simo103simo103 Member, PRO Posts: 1,331
    sorry here's the demo:

    http://gamesalad.com/game/2928
  • jjonaszjjonasz Member Posts: 7
    Thanks for the help simo, but I guess if I could figure out the movement path of the 1x1 pixel actor I could apply that to the boat actor. As there are no inputs (touch or mouse) for my boat to follow, I still need to figure out the right movement for a nice arc that would look like a boat moving.

    I'm going to try just using the regular Move behavior and slowly change the angle of the move to simulate this.
  • jjonaszjjonasz Member Posts: 7
    Hmm, this is a tough one. Or maybe I'm overcomplicating it.

    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?
  • simo103simo103 Member, PRO Posts: 1,331
    I had downloaded a demo and I can't re-find it in GS so I have zipped it here:

    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
Sign In or Register to comment.