0 votes

I'm trying to make an object go upwards when a key is pressed - this code doesn't work:

extends Spatial

var flprop
func _ready():
    flprop = get_node("flprop")
    self.set_process(true)

func _process(delta):
    if Input.is_action_pressed("drone_up"):
        flprop.apply_impulse(Vector3(0, 0, 0), Vector3(0, 10, 0))

but if I move the flprop.apply_impulse() line into the _ready function, the object does have the force applied.

in Engine by (15 points)
edited by

Apply a positioned impulse (which will be affected by the body mass
and shape). This is the equivalent of hitting a billiard ball with a
cue: a force that is applied once, and only once. Both the impulse and
the offset from the body origin are in global coordinates.

Maybe use flprop.apply_impulse(flprop.get_traslation(), Vector3(0, 10, 0))?

1 Answer

+1 vote
Best answer

Your code works as it should, working sample project link below. Did you ensure "drone_up" is defined in your input map?

Project link: https://drive.google.com/file/d/0BwnfZQAEnciAVFRaU2JNalYyVHc/view?usp=sharing

by (1,302 points)
selected by

If I add the line print("Test") to the input if statement, the line gets printed, so I know the key press is being registered

Can you see the flprop node on screen and confirm it is there? And when you key press "drone_up" do any error messages appear in the debugger?

If possible, would you mind posting a link to your scene or project?

Fixed it - flprop was hidden. Thank you!!

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.