Question by
autoBot0 · Jul 15, 2017 at 03:38 PM ·
cameratransformplayer movementcamera rotatemouse look
Player moves when camera rotates
I have a player, which is just a parallelepiped and a camera, child of the player. When the camera moves up and down (Y axis) the player moves forward or backwards proportionate to how much the camera is looking up or down. The player is sort of "falling" or "tipping over" but without actually touching the ground (I removed the rigidbody component, so there's no gravity). I am using FPSwalkerenhanced on the player and this code on the camera:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class playerLook : MonoBehaviour {
private float yaw = 0.0f;
private float pitch = 0.0f;
void Update () {
yaw += Input.GetAxis("Mouse X");
pitch -= Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
Thanks for any reply!
Comment
By the way I tried re adding the rigidbody component to lock the y axis but it had no effect whatsoever.