Question by
lucasw89 · Nov 18, 2016 at 04:53 PM ·
rigidbodyvector3camera-movementgetaxis
Getting vector 3 to move relative to camera
Hello people.
I am making a game for fun with a guy at school. I have got the camera moving with the mouse axis, and the rigidbody moving via the keyboard axis,
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
// Player Movement
public float movespeed;
public float maxspeed;
public Rigidbody Player;
private Vector3 input;
// Mouse Movement
public float speedH = 2.0f;
public float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Player.velocity.magnitude < maxspeed)
{
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Player.velocity = input * movespeed;
}
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}
But now when i move my camera, the rigidbody of course dosen't move to the new locally created X Y and Z. Would anyone be so kind as to help me?
Thanks for your time. Have a nice day.
Comment