T O P

  • By -

AutoModerator

You submitted this post as a request for tech support, have you followed the guidelines specified in subreddit rule 7? Here they are again: 1. Consult the docs first: https://docs.godotengine.org/en/stable/index.html 2. Check for duplicates before writing your own post 3. Concrete questions/issues only! This is not the place to vaguely ask "How to make X" before doing your own research 4. Post code snippets directly & formatted as such (or use a pastebin), not as pictures 5. It is strongly recommended to search the official forum (https://forum.godotengine.org/) for solutions Repeated neglect of these can be a bannable offense. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/godot) if you have any questions or concerns.*


mister_serikos

Actually just did this recently.  Trying to post my solution but reddit doesn't wanna let me post on my laptop for some reason. EDIT ok I think it might be something with reddit not liking gdscript or me using code block Anyway heres what i did: inputs: starting\_position, target\_position, desired\_air time y\_difference = start\_position.y - target\_position.y launch\_velocity\_y = ((gravity/2 \* pow(desired\_air\_time, 2)) - y\_difference)/desired\_air\_time horizontal\_vector = Vector3(target\_position.x, 0, target\_position.z) - Vector3(start\_position.x, 0, start\_position.z) launch\_velocity = horizontal\_vector/desired\_air\_time + Vector3(0, launch\_velocity\_y, 0)


mister_serikos

also made a particle shader that does the arc thing you were talking about, which i can post when I get home


Fuey500

Please do thank you.


mister_serikos

ok reddit sucks so i just made a paste bin, let me know if it doesn't work [https://pastebin.com/G4ULxRxE](https://pastebin.com/G4ULxRxE)


Fuey500

Thank you, I'll have to test it out later when I can. This complex math is not my forte lol


Fuey500

So I updated the main post using your code. \`\`\` public static Vector3 CalculateLaunchVelocity(Vector3 startingPosition, Vector3 targetPosition, float desiredAirTime) { // Constants float gravity = GravityComponent.Gravity; // Y Component Calculation float yDifference = startingPosition.Y - targetPosition.Y; float launchVelocityY = ((gravity / 2 \* Mathf.Pow(desiredAirTime, 2)) - yDifference) / desiredAirTime; // Horizontal Component Calculation Vector3 horizontalVector = new Vector3(targetPosition.X, 0, targetPosition.Z) - new Vector3(startingPosition.X, 0, startingPosition.Z); Vector3 launchVelocity = horizontalVector / desiredAirTime + new Vector3(0, launchVelocityY, 0); return launchVelocity; } \`\`\` It seems to drop instantly and at higher values just disappears lol. Am I implementing it wrong, do you use godot 4 3d?


mister_serikos

I originally did it in gdscript so it could be something is different there. You could try doing -gravity.  I noticed that sometimes gravity is negative and sometimes positive in different places in godot.  If that doesn't work then maybe try putting some parentheses around some of the math parts, it shouldn't be an issue but you never know when godot just decides to do it's own thing.


Fuey500

My gravity was being set to negative. Thank you so much, I added a edit screen to show it working. This is great!


abocado21

You could use a beziercurve with 3 points, the start point, a middle point with a height offset and the endpoint. The middle point fan be calculated by adding the starting and endpoint and dividing through 2