How to make a 2d toss mechanic

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mintPIXEL

I can’t figure out how to make a 2d toss mechanic for the life of me. Any help? Basically I want a physics object (rigid body) to follow the finger when the object is being pressed on by the finger (on a touchscreen) or a mouse, and when the finger or mouse releases the object the object keeps moving at the velocity it was at when released. Any help? Any examples would be great, Im still learning Godot, and this is making me pull my hair out.

Thanks so much!

:bust_in_silhouette: Reply From: Inces

And what have You done so far ? Post it, so we can give You a hint what to change in code.

Surely You apply some forces to your RigidBody when finger touches the screen, calculated based on the distance from body to event. Simply stop applying them when there is no touch event :slight_smile:

Hey, thanks for the response. What Im trying to accomplish works like this in other engines.
Im just at a loss to how to even start with Godot when it comes to this. Like I said, Im new. I have made a simple platform game and a few others in Godot, but I haven’t messed with physics much or touch/mouse controls.

Dropbox - Screen Shot 2021-12-15 at 12.29.28 PM.png - Simplify your life

Dropbox - Screen Shot 2021-12-15 at 12.33.52 PM.png - Simplify your life

mintPIXEL | 2021-12-15 17:36

Are these visual scripts ? I don’t know much about these.
Big difference about rigid pshysics is that You don’t have to control movement and velocity every frame. Find methods to apply_force and apply_impulse. If You call them from anywhere in any frame, they will determine movement of rigid bodies for many more frames, until force power is depleted. It is very intuitive, and Your idea of tossing object like this should be performed easily :slight_smile:

Inces | 2021-12-15 21:49