TheWorldSpins
TheWorldSpins

Reputation: 103

Godot rigidbody is not moving when force is added

I just switched from Unity to Godot, and have been having trouble with physics-based player movement. I wrote a script in GDscript that is supposed to add a force to the rigidbody. It didn't work, so I had it log a variable to the console whenever I press the button that's supposed to move the rigidbody. The variable did log to the console, so I can conclude that it is a problem with the rigidbody. Here is the code:

extends RigidBody
var Movement = Vector3()
var a : int = 1
func _ready():
    print(a)
func _physics_process(delta):
    Movement = Vector3(0, 0, 0)
    _get_input()
    add_force(Movement, Vector3(0, 0, 0))

func _get_input():
    if (Input.is_action_pressed("ui_right")):
        Movement.x = 1
        print(a)

Upvotes: 0

Views: 4465

Answers (2)

TheWorldSpins
TheWorldSpins

Reputation: 103

Oh, I'm stupid. The force needed to be more like movement.x = 100, not movement.x = 1.

Upvotes: 2

Henry Mont
Henry Mont

Reputation: 357

I think you need to use the method add force this way :

object.add_force(Movement, Vector3(0, 0, 0))

In your case it would result in something like :

self.add_force(Movement, Vector3(0, 0, 0))

Upvotes: 0

Related Questions