Hi! I am currently working on the project boost. I tried to use debug console to get the return value of Time.deltaTime, Vector3, and the mainThrust. They were never zero. However, when I print (vector3mainThrustTime.deltaTime), the value showing up in the console is (0.0,0.0,0.0). Thus, my rocket is not moving anywhere when I pressed the space bar. Later, I looked up the possible solution on the stack overflow. One possible solution is changing Time.deltaTime to Time.fixedDeltaTime, but (vector3mainThrustTime.fixedDeltaTime) give me the same result (0.0,0.0,0.0). I made it work by deleting Time.deltaTime, but it is no longer frame independent. Does anyone happen to have the same issue?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
// Start is called before the first frame update
Rigidbody rigid;
[SerializeField]float mainThrust=1f;
[SerializeField]float rotationThrust=1f;
void Start()
{
rigid=GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
processThrust();
processRotation();
}
void processThrust(){
Debug.Log(Vector3.up * mainThrust*Time.fixedDeltaTime);
if(Input.GetKey(KeyCode.Space)){
rigid.AddRelativeForce(Vector3.up * mainThrust*Time.fixedDeltaTime);
}
}
void processRotation(){
if(Input.GetKey(KeyCode.A))
{
applyRotation(rotationThrust);
}
else if(Input.GetKey(KeyCode.D)){
applyRotation(-rotationThrust);
}
}
private void applyRotation(float rotationFrame)
{
transform.Rotate(rotationFrame * Vector3.forward * Time.fixedDeltaTime);
}
}