Throw an item from player


(Bartłomiej Kalemba) #1

Hi, it’s me again (as always need help). I want to implement “throwing” item from player. So far I coded picking up item from ground.

My “head” solve: Maybe I should use tween: ?

  • tween for item going up
  • tween for item going down Maybe someone tryed to do this before?

(Elias) #2

It depends on what kind of game you make and how your item would be tossed.


(Ultima2876) #3

What kind of game is it? Side-scroller? Top-down?


(Bartłomiej Kalemba) #4

For now it’s a scroller, but I’m thinking about add vertical map also. For now I’m working with tweens. If I finished with success I’ll write it here


(Ultima2876) #5

I don’t think tweens are the best solution for that kind of thing. I find it way easier and more ‘organic’ to use simple velocities instead. For example, your player throws the object with an initial Y velocity of 30 and X velocity of 60. In your throwable object class you have gravity on the update that adds -10 to the velocity every second. Then it’s just a simple matter of adding whatever the X and Y velocities are to the X and Y position of the object every frame, and tweaking your values to make it natural. You can also slightly randomise the starting velocities to make it look cool when lots of items are thrown.

Using tweens for that kind of stuff just makes it more difficult to achieve, and harder to tweak if you want to add features later.


(Elias) #6

Does objects detects collision when they are tweened?


(Zachary Lewis) #7

If they detect collision when not being tweened, they should detect collision when being tweened.

All tweening does is update values for you, so if you’re tweening the location of an Entity, all the tween will do is update the location each frame.