i wanna make movement for RigidBody using add_force

``````extends RigidBody

export var speed := 3.0

func _physics_process(_delta):
var velocity := Vector3.ZERO

if Input.is_action_pressed('up'):
velocity.z -= speed
if Input.is_action_pressed('left'):
velocity.x -= speed
if Input.is_action_pressed('down'):
velocity.z += speed
if Input.is_action_pressed('right'):
velocity.x += speed

``````

I move a little forward and then try to stop this movement by moving backward, but it does not stop.

Godot version 3.2.3.stable.official
in Engine

It's not the `add_force()` method, but using `set_linear_velocity()` it works for me.

by (166 points)

I know this, but I need that after stopping the movement, the ball still moves thanks to the application of force

+1 vote

Hi!
So you are facing a common misconception about how addforce works: it basically adds a continuous force until removed. To apply an instantaneous force that then stops you need to switch from addforce to apply_impulse:

``````extends RigidBody

export var speed := 3.0

func _physics_process(_delta):
var velocity := Vector3.ZERO

if Input.is_action_pressed('up'):
velocity.z -= speed
if Input.is_action_pressed('left'):
velocity.x -= speed
if Input.is_action_pressed('down'):
velocity.z += speed
if Input.is_action_pressed('right'):
velocity.x += speed

apply_impulse(velocity.rotated(Vector3.UP, rotation.y), Vector3.ZERO)
``````

I hope that it helps,

by (101 points)

Btw sorry for the bold and the italic for some reason i didn't press the bold button, but even so they appeared

thanks, I will try not to forget to try it the next day

when driving forward and then backward, it starts spinning to the right. Round
maybe force should be given off-center force?

``````extends RigidBody

export var speed := 0.3

func _physics_process(_delta):
var velocity := Vector3.ZERO

if Input.is_action_pressed('up'):
velocity.z -= speed
if Input.is_action_pressed('left'):
velocity.x -= speed
if Input.is_action_pressed('down'):
velocity.z += speed
if Input.is_action_pressed('right'):
velocity.x += speed

velocity = velocity.rotated(Vector3.UP, rotation.y)

apply_central_impulse(velocity)
``````

Which rigidbody mode are you using? Rigid, Character or Kinematic?

i use rigid mode

Try changing it to character mode since that mode prevents rotation

now he not move