Quantcast
Channel: Questions in topic: "maintain"
Viewing all articles
Browse latest Browse all 19

Maintain direction regardless of rotation

$
0
0
Hey there! So, I am attempting to control my player on the X axis, with the left and right keys, which works thus far. I am then trying to layer on some rotational functionality, whereupon the player character 'leans' left or right dependant on movement. I have also been able to achieve this. However, my issue arises when the player character successfully leans in to its movement but then subsequently moves in that new direction. See figure for example. The blue square represents my player character at a standstill. While the red square represents what currently happens when it leans in to its movement. Lastly the green square represents how I would like it to act. ![Blue = standstill, Red = bad axis, Green = good axis][1] [1]: http://dl.dropbox.com/u/563418/Art%20Stuff/axis_rot_400x.jpg Here is my code thus far. #pragma strict var playerSpeed = 10.0; var playerRotation = -5; function Start () {} function Update () { var movementX = Input.GetAxis("Horizontal") * Time.deltaTime * playerSpeed; var rotationZ = Input.GetAxis("Horizontal") * playerRotation; transform.Translate(movementX, 0, 0); //dictates the movementX variables direction. In this case, obviously the X axis. transform.localRotation = Quaternion.Euler(0,0,rotationZ); }

Viewing all articles
Browse latest Browse all 19

Trending Articles





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