I’m trying to use position of mouse x to change my players forward axis so that Up arrow still moves up as the rotation is changed with mouse x
or
using mouse x to rotate camera and the players forward position is aligned with camera view.
not sure how to do this.
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
Animator anim;
Rigidbody rb;
Vector3 hitr;
Vector3 hitrn;
float speed = 150f;
void Start()
{
rb = GetComponent<Rigidbody> ();
anim = GetComponent<Animator> ();
}
void Update ()
{
Move ();
Turning ();
}
void FixedUpdate()
{
//inclines
RaycastHit hit;
Physics.Raycast (transform.position, Vector3.down, out hit);
if(Physics.Raycast(transform.position, Vector3.down, .5f))
{
transform.up = hit.normal;
hitrn = hitr - transform.eulerAngles;
transform.Rotate(hitrn.x, 0, hitrn.z);
}
}
void Move()
{
float forward = Input.GetAxis ("Vertical");
anim.SetFloat ("Speed", forward);
float sideways = Input.GetAxis ("Horizontal");
anim.SetFloat ("Direction", sideways);
Vector3 movement = new Vector3 (sideways, 0f, forward);
rb.AddForce (movement * speed);
}
void Turning()
{
if (Input.GetAxis ("Mouse x"))
{
}
}
}