- Home /
C#:"w" and "s" switch roles w/ transform.rotation of 180
I have the following line of code:
player.transform.rotation = Quaternion.AngleAxis(180,Vector3.up);
rotating my avatar 180 degrees, but after the rotation the "w" key goes backwards (stays forward for the old facing) and "s", well, you get the picture. What's the proper C# command to make my avatar turn 180 degrees and still use "w" to move forward in the new facing? Is there just one command, or a procedure I need to set up? Will it require parenting? Thanks in advance for any and all help on this!
To give you an answer we need to see your movement code (the code that process the 'w' key and makes your character move), and to understand how the camera is handled (stationary or follows the character). Typically this kind of problem is caused by using local rather than world movement or world ins$$anonymous$$d of local depending on the situation.
Okay, so, the avatar is just a camera I added a capsule collider to. The movement is an AddForce as per the Unity Tutorial Project Roll-a-Ball:
using UnityEngine; using System.Collections;
public class Avatar$$anonymous$$ove : $$anonymous$$onoBehaviour { public float speed; void FixedUpdate () { float moveForward = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(0.0f,0.0f,moveForward) rigidbody.AddForce (movement*speed*Time.deltaTime) } }
I hope this additional information will help bring the answer to light. Sincere thanks for the reply.
Your answer
Follow this Question
Related Questions
rotation relative to a transform 1 Answer
Quaternions acting up 1 Answer
how to ignore transform.position.y 3 Answers
Problems caused by non-unique Euler angle solutions 1 Answer