How do you make one end of an actor turn while the other end stays put?

So I'm making a fighting game and one of the characters is a skeletal dragon. He is going to shoot a laser beam that automatically follows the enemy. I cant seem to get the laser to turn without the other end turning as well. Can someone walk me through how to do this? I am pretty experienced with GameSalad so I will most likely know exactly what you are talking about. Thanks

Comments

  • RainbrosRainbros Member Posts: 124

    Here are the equations for an off-center rotation:

    Constrain Attribute: self.Position.X To:
    sceneX+magnitude(self.offsetX,self.offsetY)*cos(self.Rotation+vectorToAngle(self.offsetX,self.offsetY))

    Constrain Attribute: self.Position.Y To:
    sceneY+magnitude(self.offsetX,self.offsetY)*sin(self.Rotation+vectorToAngle(self.offsetX,self.offsetY))

    sceneX and sceneY are the coordinates in the scene where you want your pivot point to be. offset x and y are the distances from the center of your actor to the pivot point.

    So, for example, if the long dimension of your laser is its width and it is 20 pixels wide, you would put in 10 for offsetX and 0 for offset y. Then simply constrain the rotation of the laser using vectorToAngle to keep it pointing at the player.

    (Credit goes to @RThurman and @Rob2 for coming up with these formulas.)

  • SocksSocks London, UK.Member Posts: 12,822
Sign In or Register to comment.