AddRelativeForce() does nothing

So I’m going through the project boost course at the moment and I’m on lesson 37. The AddRelativeForce() method isn’t doing anything but I’m seeing my key input is still being logged to console. I’m not sure how to proceed, should I switch to using Rigidbody.velocity?

Here’s my code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Movement : MonoBehaviour

{

Rigidbody rb;

[SerializeField] float rocketThrust = 2f;

[SerializeField] float velocityX = 0f;

[SerializeField] float velocityY = 10f;

[SerializeField] float velocityZ = 0f;

// Start is called before the first frame update

void Start()

{

    rb = GetComponent<Rigidbody>();

}

// Update is called once per frame

void Update()

{

    ProcessThrust();

    ProcessRotation();

}

void ProcessThrust()

{

    if (Input.GetKey("space"))

    {

        Debug.Log("Pressed space - thrusters active");

        rb.AddRelativeForce(Vector3.up * rocketThrust);

    }

}

void ProcessRotation()

{

    if (Input.GetKey("a"))

    {

        Debug.Log("Rotating left");

    }

    else if (Input.GetKey("d"))

    {

        Debug.Log("Rotating right");

    }

}

}



Hi Andrew,

Welcome to our community! :slight_smile:

From what I see in your screenshot, you seem to be using an ancient old version of Unity. In your console, the message ‘Pressed space - thrusters active’ appeared, so we can assume that your code works.

There was a strange bug in some old versions of Unity. You had to select the rocket in the Hierarchy to be able to fly it properly. If you didn’t have it selected, it refused to fly.

Try to select the rocket.

If that didn’t work, I would suggest to install the latest stable version of Unity.


See also:

Your Rigidbody has ‘is Kinematic’ check. Uncheck it.
image

1 Like

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

Privacy & Terms