0
\$\begingroup\$

I'm currently trying to create an area that would somehow push objects to a specific direction. (and also apply angular drag if possible)

I'm currently new to Unity and Godot. I have already seen this in Unity tutorial and checking if this is also possible in Godot.

I have a RigidBody2D (with gravity) that falls down on an Area2D.

I'm currently stuck at this code..

func _on_Area2D_body_entered(body):
    body.apply_impulse(Vector2(),Vector2(0,-50))

..but it only applied it once after entering the are and not continuously applying force until the object exited the area. I tried using add_force but it gave the object a constant speed and direction and not falling back down.

\$\endgroup\$
4
  • \$\begingroup\$ An impulse is, by definition, instantaneous: it only changes the velocity at a specific point in time. Therefore it's definitely not what you need. Add_force would be the one you need. Can you describe better what is the issue with it? \$\endgroup\$
    – Turms
    Jun 1, 2019 at 17:54
  • \$\begingroup\$ @Turms I tried add_force but it made the object goes up and never came down even if at first it goes down because of gravity. \$\endgroup\$ Jun 1, 2019 at 18:17
  • \$\begingroup\$ Is the added force parallel to gravity? Is it pointing against gravity? Have you tried tuning its intensity? Are you sure you add the force only once upon entering the area, and removing it after the object has left the area? \$\endgroup\$
    – Turms
    Jun 1, 2019 at 22:16
  • \$\begingroup\$ @Turms it is against gravity. I added a force going up. Yes I tried lowering the intensity but still it continues to go up in a constant speed. I'll try that idea of removing the force after it left the area. I'll get back to you later and tell you what happened. \$\endgroup\$ Jun 2, 2019 at 5:18

2 Answers 2

1
\$\begingroup\$

Use the equivalent of OnCollisionStay (I'm not sure what that would be in Python). Also, use add force not impulse. Impulse is instantaneous, force is over time.

\$\endgroup\$
0
\$\begingroup\$

I was able to do what I want by applying force on entry and applying opposite force on exit.

func _on_Area2D_body_entered(body):
    body.add_central_force(Vector2(0,-500))

func _on_Area2D2_body_exited(body):
    body.add_force(Vector2(),Vector2(0,500))

Thanks for the clarification regarding impulse and force. I'm just new to game development so I'm still having trouble on understanding some terms.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .