Some problem with movement
Now I am new to unity and learning it.
I followed a rigid body movement script tutorial and made one then I added a rotation script so I can look around with a mouse in the game. But when I move my mouse the camera rotates but the movement does not rotate which means that if i moved to the left and clicked"w" it would still move to my right how can i fix this . Where do i need to paste my code idk so i am pasting it in here.
My movement script
using UnityEngine; public class scr : MonoBehaviour { [SerializeField] private Rigidbody playerBody; public Vector3 inputVector;
void Start()
{
playerBody = GetComponent<Rigidbody>();
}
void Update()
{
inputVector = new Vector3(Input.GetAxisRaw("Horizontal") * 25, playerBody.velocity.y , Input.GetAxisRaw("Vertical")* 25);
playerBody.velocity = inputVector;
}
}
My camera rotation script
using UnityEngine;
public class GG : MonoBehaviour { public float speedH = 2.0f; public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
void Update()
{
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}}
Your answer

Follow this Question
Related Questions
Moving a gameobject from point A to D thru B and C 1 Answer
Teleporting 2D object once 1 Answer
Movement scrip 0 Answers
How can I use both mouse and keyboard to do the same thing? [SOLVED] 1 Answer
How to code spaceship evasive maneuvers? 0 Answers