The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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 (27 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 (4,088 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 Frequently asked questions and 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 [email protected] with your username.