this is my code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class movement : MonoBehaviour
{
// Start is called before the first frame update
public Rigidbody rBody;
public bool jmpRDY;
public float Hinput;
public float Vinput;
public bool isToGround;
public float CICTPY;
public float Sim_CICTP;
public float rotationSpeed;
Vector3 movementDirection;
// Start is called before the first frame update
void Start()
{
rBody = GetComponent<Rigidbody>();
jmpRDY = false;
isToGround = false;
}
// Update is called once per frame
void Update()
{
if(transform.position.y <= CICTPY){
SceneManager.LoadScene( SceneManager.GetActiveScene().name );
}
if(Input.GetKeyDown(KeyCode.Space) && isToGround){
jmpRDY = true;
}
Hinput = Input.GetAxis("Horizontal") *5;
Vinput = Input.GetAxis("Vertical") *5;
GameObject playerCamera = GameObject.Find("player camera");
Sim_CICTP = playerCamera.transform.position.y;
// Debug.Log(Sim_CICTP);
Quaternion toRotation = Quaternion.LookRotation(movementDirection, Vector3.up);
transform.rotation = Quaternion.RotateTowards(transform.rotation, toRotation, rotationSpeed * Time.deltaTime);
}
private void FixedUpdate(){
if (jmpRDY && isToGround){
rBody.AddForce(Vector3.up *7 , ForceMode.VelocityChange);
jmpRDY = false;
isToGround = false;
}
rBody.velocity = new Vector3(Hinput,rBody.velocity.y,Vinput);
}
void OnCollisionEnter(Collision collisionInfo){
if(collisionInfo.collider.tag == "terrain"){
isToGround = true;
}
}
}
in this code the Sim_CICTP is my camera rotation...
it is the value between 0 to 360
I want to make my player move accordingly to that value…