Ask here your questions to get help using GDevelop.
User avatar
By TheATOM
#68054 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.
User avatar
By Lizard-13
#68060 Sadly one can't make a complex task simple just because you're new to GD, that would be cool, though :D
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:
(6.3 KiB) Downloaded 39 times

The other option is easier, just use the physics behavior on the ball and ground :P
By Umar
#68067 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
User avatar
By TheATOM
#68106 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?
User avatar
By Lizard-13
#68114 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? :?

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 :)