Time.deltaTime and Time.fixedDeltaTime issue

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);
    }
}

Hi,

Can you link your code, else its very hard to guess whats going on.

You can link it between 3 grave symbol top, and 3 grave symbol bottom,
then it will show like this:

code goes here

Thank you, I think I figure out the issue. The magnitude of (Vector3.up * mainThrust*Time.fixedDeltaTime) have to be larger than the mass of the object in the rigid body in order for the rocket to move. (0.0,0.0,0.0) as the product might be some minor error in my device.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms