We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I'm new here so excuse me if i do anything wrong. I'm trying to program a "Worms" like game, where you have a character in one side and you want to hit the other player in the other side of the map. I was trying to throw a projectile by clicking on my player1 body and then dragging the mouse back and releasing it so the projectile had a different angle and velocity depending on the position of the mouse in relation to the player 1 body. I'm using the box2D physiscs library in my project. If anyone could help me trying to understand how this would work i really appreciate it. Thank you.
Answers
Get the point of your first click on the character with mousePressed() and save the mouse coordinates(mouseX and mouseY) and then capture the point of release with mouseReleased(). By subtracting the former values from the latter you get the changes in x and y and can set the projectile speed accordingly.
This might be a stupid question, but how can i save the mouse coordinates of the point when i use the mousePressed()? I'm still beggining so i lack a lot of basic knowlegde.
Hello @andrecota
So,
o what angle would you apply for each thrown, is basic, that way you could try more attempts in the same place. o what initial speed would you apply for each thrown
If you have some code it'd be good in order to give some solutions
And the player class:
But i havent implemented anything sucessfully in the main tab.
You could do something like this
@andrecota Please format your code. Edit post, select code and hit ctrl+o. Ensure there is an empty line above and below your code.
@Sayid Your example is valid. To clarify, there are processing variables already tracking previous mouse coordinates: pmouseX and pmouseY:
https://processing.org/reference/pmouseX.html
https://processing.org/reference/pmouseY.html
Kf
Ok i formated it
You need to provide a minimum running code showing your challenge. In addition, there are classes definitions missing in the code you provided: Body and Vec2.
Kf
I don't see the use of that - pmouseX and pmouseY change every time in draw (at least they will if they can), and also each time a mouse event is called.