I’m a beginner and asking on How will i be able to put the Camera relative controls in my current Codes.
thank you for all the help.
using UnityEngine;
using System.Collections;
public class Movements3 : MonoBehaviour {
public Camera _camera;
public float moveSpeed = 5.0f;
public float jumpSpeed = 5.0f;
private CharacterController Player;
public float gravity = 10.0f;
private float fallSpeed;
private bool isGrounded;
// Use this for initialization
void Start () {
Player = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update () {
IsGrounded();
Fall();
Jump();
Move();
}
void Move()
{
// Vector3 forward = _camera.transform.TransformDirection(Vector3.forward);
float xSpeed = Input.GetAxis("Horizontal");
if (xSpeed != 0) Player.Move(new Vector3(xSpeed, 0) * moveSpeed * Time.deltaTime);
}
void Jump()
{
if (Input.GetButtonDown("Jump") && isGrounded)
{
fallSpeed = -jumpSpeed;
}
}
void Fall()
{
if (!isGrounded)
{
fallSpeed += gravity * Time.deltaTime;
} else
{
if (fallSpeed > 0) fallSpeed = 0;
}
Player.Move(new Vector3(0, -fallSpeed) * Time.deltaTime);
}
void IsGrounded()
{
isGrounded = (Physics.Raycast(transform.position, -transform.up,0));
}
}