0 votes

I have a rigidbody that I move with

if Input.isactionpressed("Forward"):
addcentralforce(toglobal(Vector3(-100,0,0)))
if Input.is
actionpressed("Left"):
add
centralforce(toglobal(Vector3(0,0,100)))

etc.

The problem is that when I move it left, right, up, or down it starts moving forward too, even though as far as I can tell there's no reason for it to

in Engine by (25 points)

can you supply more code and in "code format" to debug and forward is -x?

https://github.com/frenchma/Game-stuff.git

this is all the code I've got in the file

I've tested it ... no forward movement in my case.
Are your sure that you dont messed up the keybindings?
Maybe you have the forward key bindet to the other directions too!?

The keybinds are all good, maybe it has something to do with the physics?

I've zipped up the game files and stuck that on the github, if anyone wants to take a look

1 Answer

+1 vote
Best answer

Ah, now i see.

The problem is the force vector. You have addcentralforce in a global direction but you have to remove your global offset (global.origin)

if Input.is_action_pressed("Port"):
    add_central_force(to_global(Vector3(0,0,100))-global_transform.origin)
if Input.is_action_pressed("Starboard"):
    add_central_force(to_global(Vector3(0,0,-100))-global_transform.origin)

this does the trick.

by (2,424 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories