Time.deltatime

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rocket : MonoBehaviour
{

Rigidbody rigidBody;
// Start is called before the first frame update
void Start()
{
    rigidBody = GetComponent<Rigidbody>();
}

// Update is called once per frame
void Update()
{
    ProcessInput();
}

private void ProcessInput()
{
    if (Input.GetKey(KeyCode.Space)) //can thrust while rotating
    {
        rigidBody.AddRelativeForce(Vector3.up*Time.deltaTime*60);
    }
    
    if (Input.GetKey(KeyCode.A))
    {
        transform.Rotate(Vector3.forward*Time.deltaTime*50);
    }
    else if (Input.GetKey(KeyCode.D))
    {
        transform.Rotate(-Vector3.forward*Time.deltaTime*50);
    }

}

}

Hi Karol, it will be better if instead of using the 60 and 50 as “hard number” in your line of code, you should use a variable for these numbers.

Ok thanks.

Privacy & Terms