Detect linear velocity in a circular movement.

steve86steve86 Member Posts: 806
edited November -1 in Working with GS (Mac)
Hey guys.

I've been wrapping my mind a bit on this one and I just cant get a hang of it. I was wondering if someone can help me.

I have an actor that moves in a circle. I program that actor to move in a circle using the following formulas:

constrain attribute: self.position.X to: 40*cos(self.Time*600%360)+240

constrain attribute: self.position.Y to: 40*sin(self.Time*600%360)+160

This works very well but I'm trying to make the actor face forward on the direction that he is going. The way I normally do this is have a rule that says:

When linear velocity X > 0 display image of actor facing right. Otherwise (when linear velocity X < 0) display image of actor facing left.

But on the circular movement actors, the linear velocity is always 0, because im not using any move behaviors.

Any idea how to detect if the actor is moving right or left so I can change the image of the actor facing right or left.

Thank you very much.

Steve

Comments

  • steve86steve86 Member Posts: 806
    anyone?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    I'm not sure that I completely understand, but you can use this:

    Constrain Attribute: self.Rotation to: vectorToAngle( self.Position.X -240, self.Position.Y -160)

    (the 240 and 160 are just the center of the screen, they can whatever point you want.)

    That will make the actor face the outside of the circle as it rotates. If you simply want to have the actor ONLY face left or right, you can base that on it's X position relative to the center point. i.e. > 240 face right, < 240 face left.

    Also, in your above formulas, %360 is not necessary.
  • micksolomicksolo Member Posts: 264
    Constrain Attribute: self.Rotation to: vectorToAngle(LinearVelocityX, LinearVelocityY)

    Should work.
  • steve86steve86 Member Posts: 806
    thanks both for your help with a few tweaking of those formulas worked like a charm
  • micksolomicksolo Member Posts: 264
    out of interest can you post exactly what you did please? Just so the next person who comes along will be able to get the correct info.
Sign In or Register to comment.