How to make a character throw a object

I am making a platformer game and I want my main character to throw a ball at the enemies to hurt them. I would like some code to make that ball bounce, be affected by gravity, and lose height over time.
Could someone tell me what code I need to make that happen and to tell me what to edit to get a different bounce height.
EDIT: I am quite new at gdevelop so I would like it to be easy.

Sadly one can’t make a complex task simple just because you’re new to GD, that would be cool, though :smiley:
I see two options here, the first one is set the ball speed with variables (speed x and speed y), modify the speed y with the gravity, move the ball manually with the speed variables and each time the ball collides with the ground make it bounce (invert the speed y) and multiply it by an “elasticity” factor, lower the elasticity means less bouncy, here is an example with elasticity = 0.7:
BounceOnGround.zip (6.3 KB)
The other option is easier, just use the physics behavior on the ball and ground :stuck_out_tongue:

I will try that, thanks :slight_smile:

Well I have a really similar events written for my enemies… When I will come back from the job I will give you the logic. It is not exactly what you asked for… but it is very similar. May be it will help you

I tried both of lizard options for doing it and both didn’t work. Is there a tutorial on this somewhere?

There’s an example in my post, it just lack comments.
Maybe you’ve a bad event?

Yes, there might be a bad event… I changed the source object to the platformer behaviour and the ground to platform, to see if the platformer behaviour was the problem and it worked fine. I renamed the objects to match the objects that I am using. I checked the code for any variables or objects I misspelled. I typed out the codes out instead of coping and pasted. Nothing seemed to work. I found out that you could use JavaScript code instead of events, but I don’t know how to write any sort of code. Would it be possible to use JavaScript instead?

Wait man, as you can see it can be done, you’ve the events so it can be done. There is no sense to do it in JavaScript because the number of conditions/actions will be the same, the events are using simple math/physics (gravity, speed and position) and you can’t avoid it with code… and has even less sense if you don’t know programming, why make it the hard way? :confused:

If you want, you can zip your project (game.json file and resources), upload it online (Mega, Google Drive, Microsoft OneDrive, etc.) and send me the download link in a private message to check it out. Surely it’s a small syntax error or just a mixed event position :slight_smile:

Yes I will send that to you sometime when I can get to it. I include a readme file for further instructions. Thanks

I have sent you the link to the game. NOTE: the hitbox, the level and just about everything is incomplete.

Ok, get it, there are two problems:

  • The first one is simple, instead “Do + Variable(gravity)*TimeDelta() to variable speed_y” you are doing "Do = ", change the “=” for a “+”.
  • The second one is like a bug, GD shouldn’t allow you to use “-” in objects names, only “a-z”, “A-Z”, “0-9” and “_”, change the objects names with dashes for underscores, GD will automatically rename the objects in the events too, but check the expressions to fix the names yourself.
    A way to notice it is in expressions, when you have an object called “Throw-Unripened” and use it in an expression, for example “Throw-Unripened.Variable(speed_x)”, GD should warn about an invalid expressions, GD tries to subtract Unripened.Variable(speed_x) from Throw and has no idea what those are :slight_smile:
    More about the slash thing here: https://github.com/4ian/GDevelop/issues/623