Can someone clarify this? - rotate to position query

Hello everyone,

Have been absent recently, but back with avengence (and ignorance, presumably!)

I'm experimenting with rotating an actor. I want a bad guy actor to rotate to face by hero actor, wherever he may be on the screen. Rotate to position seems to be the most likely behaviour for this, but having trouble. Think this thread might hold the answer;

http://forums.gamesalad.com/discussion/60644/rotation-problems

But I'm in the dark as to exactly what BBEnk explanation means. What's all that vectortoangle stuff all about? :s

Jim (confused as always!)

Best Answer

  • wcsd9739wcsd9739 Posts: 37
    Accepted Answer

    Rotate to Position stops once it faces that exact direction, so it's better to do what he said:

    make a rule when mouse is pressed then add a constraint attribute self.rotation to vectorToAngle( game.Mouse.Position.X - self.Position.X , game.Mouse.Position.Y - self.Position.Y )

    Basically this makes it so the whole vectorToAngle expression comes out as the angle you are trying to face. In your case you would want to put this Constrain Attribute behavior on your 'bad guy actor':
    Constrain [self.rotation] to [vectorToAngle(game.HeroX-self.position.X, game.HeroY-self.position.Y)]

    If your game is only going to use one scene, you can use scene.[layer].Hero.position.X instead of "game.HeroX" (and again for "game.HeroY")

Answers

  • mysticjimmysticjim Member Posts: 30

    Thanks for that, that has helped - however my question was really what is the vectortoangle function? At the time I asked I wasn't actually aware of it's existence, so reading that thread was complete double-dutch to me!

    Whilst waiting for a reply I actually managed ot find a youtube tutorial on the kind of rotation I was trying to impliment - although it didn't fully explain the vectortoangle function, it did give an example of it's use and I managed to view the code example and figured it out from there...Sort of! Your guidance has helped fill in a few blanks too, so thanks again!

Sign In or Register to comment.