1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

[solved]z axis & physics rotation

Discussion in 'Programming' started by chefdez, Feb 14, 2020 at 4:21 PM.

  1. chefdez

    chefdez Member

    Joined:
    Sep 17, 2016
    Posts:
    91
    Hello, I currently have a z axis that rotates 360 degrees when pressing arrow keys

    When I get into a car I would like to lock the z axis in place and have it turn with the vehicle so I created a custom direction variable
    Code:
    if global.inCar = 1 { // will eventually change this to a state
       carRotation = phy_rotation;
       if (carRotation < 0)
       {
           carRotation = 360;  
       }
       if (carRotation > 360)
       {
           carRotation = 0;
       }
       global.z = carRotation
    }
    
    What I am trying to do is set my carRotation to phy_rotation within 360 degrees. The issue I have is that when phy_rotation will eventually fall below 0 or go above 360 so the camera stops rotating because carRotation is locked within this range. If anyone could help that would be great! Thank you
     
  2. Jordan Robinson

    Jordan Robinson Member

    Joined:
    Jun 22, 2016
    Posts:
    94
    Why dont you keep the phy_rotation variable between 0 and 360 instead of clamping the car angle?

    To keep it looking smooth, do something like if phy_rotation is less than 360 then phy_rotation += 360 or if phy_rotation is greater than 360 then phy_rotation -= 360

    Then you could just set the car_rotation = phy_rotation and it will always be between 0 and 360
     
  3. chefdez

    chefdez Member

    Joined:
    Sep 17, 2016
    Posts:
    91
    Thanks Jordan I drew a blank on that one, I do that with speed and grav all the time lol!
     

Share This Page