AddRelativeForce not working on my rocket

Hi, I have added below command in “Movement” script. But nothing happen when I hit “space” to my rocket.

Thanks.

rb.AddRelativeForce(1,1,1);

Hi,

Welcome to our community! :slight_smile:

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Have you tried to save your script again?

Hope this helps :slight_smile:


See also;

I’m having the same issue. I even went in and copied and pasted the code directly from the Assets/Scripts/Movement.cs · 3e8f1d567782e6b22843580bf30decf91a5d6a84 · GameDev.tv / Complete Unity 3D / ProjectBoost · GitLab site… It works when I put in the rb.AddRelativeForce(1,1,1); piece (it falls over and moves), but as soon as I change it to 0,1,0 it does nothing.

Again, even after I copied the exact code over, it does nothing… (Mass .2, Drag 0, Angular Drag .05)

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

public class Movement : MonoBehaviour
{
Rigidbody rb;

// 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(KeyCode.Space))
    {
        rb.AddRelativeForce(Vector3.up);
    }
}

void ProcessRotation()
{
    if (Input.GetKey(KeyCode.A))
    {
        Debug.Log("Rotating Left");
    }
    else if (Input.GetKey(KeyCode.D))
    {
        Debug.Log("Rotating Right");
    }
}

}

Hi Daisy,

Depending on how large your rocket is, try to use higher force values, e.g. 10f. If that worked, modify the value until you are happy with the movement.

Which version of Unity do you use? Try to select another game object while playing your game. In some versions, there is a strange bug preventing the rocket from flying properly if it is selected in the Hierarchy. This problem is restricted to the Unity Editor.

1 Like

Try lowering the mass value. I had the same issue.

1 Like

Fixing the mass cleaned up the issue. Thank you! I’m using Unity 2018 right now.

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

Privacy & Terms