- Home /
Question by
Lord-Kappa · Jul 27, 2019 at 12:06 PM ·
camerarotationmouseprogrammingbeginner
Player does not follow rotation direction
At the moment the camera and player both rotate but when i move the mouse, player and camera rotates but the player keeps going forward instead of following rotation direction.
I don't know if this is any help but player object is a parent of target object and target object is a parent of camera.
here is my player script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed;
public float jumpForce;
public float gravity;
public float temp;
public CharacterController ch;
// Start is called before the first frame update
void Start()
{
ch = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
if (ch.isGrounded)
{
if (Input.GetButtonDown("Jump"))
{
temp = jumpForce;
}
}
else
{
temp -= gravity * Time.deltaTime;
}
Vector3 playerMovment = new Vector3(hor, temp, ver) * speed * Time.deltaTime;
ch.Move(playerMovment);
}
}
and here is my camera script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public float rotationSpeed = 1f;
float mouseX, mouseY;
public Vector3 offest;
public Transform target;
public Transform player;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
mouseX += Input.GetAxis("Mouse X") * rotationSpeed;
mouseY -= Input.GetAxis("Mouse Y") * rotationSpeed;
mouseY = Mathf.Clamp(mouseY, -10, 60);
//transform.position = target.position + offest;
transform.LookAt(target);
//transform.rotation = Quaternion.Euler(mouseY, mouseX, 0);
target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
player.rotation = Quaternion.Euler(0, mouseX, 0);
}
}
Any help would be greatly appreciated.
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
"Perfect" Free Rotation Method? (like Blender) 2 Answers
Rotation always changing values! 1 Answer
Mouse Orbit snapping issues 0 Answers
Screen.lockCursor messes my rotation 1 Answer