C# finding the axis of a characterobject
Alright, so I have a characterobject with a camera bound to it. It effectively moves with the wasd keys, and rotates when the mouse reaches the edges of the screen. The problem I have is that the movement for the wasd keys is based on the world axis ("Horizontal" and "Vertical",) when I need it to be based on the character's axis. That is, when he rotates, it doesn't affect the direction wasd moves him.
To specify, the movement code is this:
void FixedUpdate(){
float h = Input.GetAxisRaw("Horizontal");
float v = Input.GetAxisRaw("Vertical");
Move(h, v);
}
void Move (float h, float v){
movement.Set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.MovePosition (transform.position + movement);
}
The rotation code is handled here:
void Update()
{
if (Input.mousePosition.x >= Screen.width - mDelta)
{
transform.rotation = transform.rotation *
Quaternion.Euler(0, 1, 0);
}
if (Input.mousePosition.x <= 0 + mDelta)
{
transform.rotation = transform.rotation *
Quaternion.Euler(0, -1, 0);
}
}
I believe I need to change "Horizontal" and "Vertical" to whatever the characters' axis are, but I'm not sure how to find them.
Your answer
![](https://koobas.hobune.stream/wayback/20220612135128im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
moving an object continuously between waypoints 0 Answers
2D Object following the cursor without glitchyness at the center 0 Answers
Game Object jumps to z-axis 0 Answers
Jump is higher then normal 0 Answers
Car coding help 0 Answers