Camera Rotation Problem - Help needed

StoneclipseStoneclipse Member, PRO Posts: 130
Hi I am making my game to have the camera follow my actor rotation. I followed this video and managed to have the HUD stays in place when rotating.



However the problem is how can i add a score actor and have it stay in place when rotating the camera? Help pls. I have been working on this the whole afternoon and still can't get it to work. I know you have to use sin and cos but i have no idea about the exact equation.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Its a little complicated but here goes. First, you would need to figure out the angle of the score actor from the middle of the scene. And then you need to figure out the distance from the middle of the screen.

    So lets say you want the score actor to be in the upper left portion of the scene. The angle for upper left would be something in the range of 135 degrees. The distance from the center of the scene might be 200 pixels. The behaviors would look something like this in an unlocked actor:

    Constrain Attribute:[self.rotation] To:[- scene.Camera.Rotation]
    Constrain Attribute:[self.Position.X] To:[200*(cos(- scene.Camera.Rotation +135))+( scene.Camera.Origin.X +( game.Screen.Size.Width /2))]
    Constrain Attribute:[self.Position.Y] To:[200*(sin(- scene.Camera.Rotation +135))+( scene.Camera.Origin.Y +( game.Screen.Size.Height /2))

    Once you get it working, the only changes you will need to make are messing with the angle (135) and the distance (200) until you get the actor placed where you want. All the rest never changes.
  • StoneclipseStoneclipse Member, PRO Posts: 130
    @RThurman Hey thanks for the help. So the distance is basically the magnitude function and the angle we can use the VectorToAngle function?
  • StoneclipseStoneclipse Member, PRO Posts: 130
    I don't know what went wrong but the actor didn't appear on the scene
  • StoneclipseStoneclipse Member, PRO Posts: 130
    Okay I found out that you can't use the vectorToAngle function.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @DimensionScope -- Get things working yet? Also, depending on how you use it, vectorToAngle should work just fine.
  • StoneclipseStoneclipse Member, PRO Posts: 130
    @RThurman Yeah I managed to get it to work! Thanks!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Great! Glad its working for you.
Sign In or Register to comment.