Hi!
So you are facing a common misconception about how add_force works: it basically adds a continuous force until removed. To apply an instantaneous force that then stops you need to switch from add_force 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,
Btw sorry for the bold and the italic for some reason i didn’t press the bold button, but even so they appeared
MikeSundaysGameDev | 2021-04-10 09:49
thanks, I will try not to forget to try it the next day
Timofey | 2021-04-10 20:11
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)
Timofey | 2021-04-11 08:41
Which rigidbody mode are you using? Rigid, Character or Kinematic?
MikeSundaysGameDev | 2021-04-11 08:46
i use rigid mode
Timofey | 2021-04-11 09:55
Try changing it to character mode since that mode prevents rotation