Calculate if jump is possible
Hey, I'm working on a 2D grid game (think Terraria), I want to check if a monster can make jump from point A (start) to B (target). It can adjust its horizontal/vertical speed to hit smaller/bigger jumps, same as the player can (for example by holding space for longer to jump higher).
So I'm calling this function
CanMakeJump(monster.gridPos, target.gridPos, maxJumpPower, someGravityValue)
I have no clue if my formula is even right, I'm getting weird results partially because I don't know how to incorporate horizontal velocity which should be based on monster's movementSpeed
statistic.
Code: https://pastebin.com/7WT8ULBSPastebin
```csprivate float CanMakeJump(Vector2Int start, Vector2Int target,...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
15 Replies
you might have more success finding help in unity server
$unity
yup, already asked there but didn't receive any answers
well to me it looks like you are bruteforcing the solution.. but to my understanding if you want to jump from a to b you can just follow basic math formula and then check if the calculation is inside possible jumppower
would be couple of lines without loops instead of your solution
the only thing you might want to check aswell then would be if you bump your head on the jump trajectory
but I still need to bruteforce some solutions
check this case:

there is a lot of possibilites on how this jump can be done
some are valid and some not
since i dont see any jumpforwardvelocity that affects how far forward the jump is i asumed the distance jumped is proportional to jump height
so either the lower one would never reach the target or the higher one overshoots
since i dont see any jumpforwardvelocityWhat do you mean? I don't have that in code, if thats what you are saying. I wasn't sure how to include it in the calculations
lets say from standstill jump 1 meter high, you get 1 meter far, when you jump 2 meter high you get 2 meter far..
so now you do the jumping while running your 1 meter high jump now gets you 2 meters and you 2 meter jump 4 meters... <- this is what i mean by jumpforward velo
and like i said above i dont see that anywhere in your code so only option is a "standstill" jump which is calculable.. eg if i take the values again.. if i want to jump 1.5m far i have to jump 1.5m high
this is obviously super simplified, but the thought should hold
I guess this could work for now, but I want to push it further to make it work in a more sophisticated way
I’m trying to make AI slightly more engaging to fight
I have pretty nice behavioral system in place, but this math kills me
doesnt unity have a navmesh equivalent for 2d?
im not a gamedev therefore legitimate question
if it has doesnt it provide the necessary funtionality?
It has navmesh, but its useless in this case
maybe a different plan instead of doing arbitrary calculations, you do baked ones..
but that would only allow jumping over predetermined obstacles
dunno what your other requirements look like
player can break/place tiles so that won't work here