#Top down 2D gravity/yeeting

14 messages · Page 1 of 1 (latest)

hybrid drum
#

How do I make an item like a coin fly out of another object with somewhat realistic gravity, but because it's top down 2D it should stop at some point? like this. thanks!

trail ferry
#

Since its top down, you'd best pick a end position and then move it from start to end with an easeinout function so it moves slowly at the start and at the end. Then while it moves you increase the size of the object and decrease it again, to simulate it getting closer to the camera.

#

Essentially
move from pos 1 to pos 2 in set time, do so by using easeinout function.
at same time scale from start size to max size to end size in same set time.

hybrid drum
#

ohhmmmm

trail ferry
#

Well you could start easier and make use of some built in stuff

Logic would be like this:

Create a coin Thats a rigidbody object with collision shape as a scene

Spawning:

  • create instance variable
  • instantiate the coin packedscene and write it into the instance variable
  • apply velocity in a random direction to the instance (the coin).
#

If this all sounds like voodoo to you, I would highly recommend watching this video: https://www.youtube.com/watch?v=nAh_Kx5Zh5Q

Its long but it'll give you everything yuou will need to implement a coin like this (and other things as well)

This video is sponsored by NordPass Business: An amazing password manager that allows you to securely store and access unlimited passwords, including wifi credentials and credit card information. You can use it for yourself or for entire teams or share your own passwords easily.

You can get a 3 month trial at:
https://nordpass.com/clearcode/

...

▶ Play video
#

I can't write you code to copy-paste

#

@hybrid drum

hybrid drum
#

thanks!

trail ferry
# hybrid drum thanks!

There might be better ways but since its top down, you'll have to fake gravity on the Z axis because it doesnt exist

hybrid drum
#

yeah

#

i might remove the gravity and just apply a random velocity anyway - it might be nice

halcyon kayak
#

The easiest is probably to not worry about gravity at all and just get the direction of the box and then write a tween to move the item from the center of the box in the direction by a certain amount.