Quantcast
Channel: Questions in topic: "correction"
Viewing all articles
Browse latest Browse all 41

keeping the player upright

$
0
0
In my game I want to have the player able to go up inclined surfaces (I know that there is a limit to angle, and such), but I have the problem that when the angle of the player breaks a 45 it starts free spinning, and can easily end up upside down. I have implemented a `input.GetKey` to put the character right side up, but I need to figure out how to have a script do it automatically. when I try this my character doesn't rotate at all. Note: on reset correction Y-rotation is preserved. //current solution (character will not rotate at all about the x, or z axes.) if((transform.rotation.eulerAngles.x<-180)||(transform.rotation.eulerAngles.x>180)|| (transform.rotation.eulerAngles.z<-180)||(transform.rotation.eulerAngles.z >180)){ // preserve Y rotation float currentLook = transform.rotation.eulerAngles.y; // put character to default rotation transform.rotation = Quaternion.identity; // re-introduce Y rotation transform.Rotate(0,currentLook,0); } // works as intended if(Input.GetKey(".")){ // preserve Y rotation float currentLook = transform.rotation.eulerAngles.y; // put character to default rotation transform.rotation = Quaternion.identity; // re-introduce Y rotation transform.Rotate(0,currentLook,0); } EDIT: currently I have my character wrapped in a box collider, and I would like to have it so that it can go up inclined planes, but I don't want to have the player flip over. does anyone have any ideas on how to keep the player from flipping over (might be using same logic for my AI agents if they have the same problem) - I still want the player to be able to rotate with respect to all axes, - once the transform breaks 90 with respect to either x, or z to have it go back to identity (then rotate by the previous y rotation) - and possibly let collision resolution(gravity) put it back to where it needs to be.

Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>