So i have a simple cannon scipt show in the image. Everything works there but i want to somehow detect if a player will go over a set amount of studs (ex: 10k studs). since i have another script that will detect if a player touches it (it will eventually will) but it has a limit hence the need, after that i would jsut detect it and change accordingly. ive tried calculating the math, but it was still off by quite a bit around 30% (maybe just me) i could just do it manually, which would work but would be less efficient and im planning to do this multiple times with different areas and such so i just wanna check if there is a way.
#Need help on finding a way to detect where a player will go before it actually goes there
1 messages · Page 1 of 1 (latest)
wdym?
nvm you want to detect the amount of stud the player will reach?
yes before the play goes there
player*
although i dont think theres a way unless doing the math which is still unreliable cuz of the physics engine
so i think i should just prolly do it manually
so what you need to do
first get the starting position
actually i dont think my calculation would work
i already tried to calculate a few hours ago which thought was pretty accurate but it pretty different from the actual result, so im not sure if im dumb or it is the physics engine
** You are now Level 8! **
i was going to say put the starting pos in a var then the end pos will be like any number and then just run a loop( runservice) then keep checking the pos of the player and you can predict it before it hits that number
oh alr
Wait why not detect it on the client
maybe it might be more accurate there
wdym how so?
oh yeah
good point
ill try
actually wait no i dont think itll make much of a difference
since im calculating with server physics no?
wdym by context
wait its like 2 am and im a bit sleep deprived so i apologize if im being a dumbass rn
its so that the player doesnt like go over studs, since i have a plate that a player should eventually reach, but that plate has a limit which is 10k studs
why dont you stop the player when he reaches 10k stud then
like set the player's velocity 0 or am i understanding this wrong
yeah thats what i was thinking too, but if i can adjust so he does reach 10k, id feel like that would look way better.
if i dont find a way thats prolly what im gonna do or manually find the power
i just wanna try find a way just for the sake of quality of life
you could calculate the speed , if the speed is constant then you can then predict the 10k stud
slr my internet went out lmao. and that its not constant since im using vertical velocity also which is affected by gravity and i have a body velocity which i quicky destroy to make a more of a cannon feel.
there should be a way maybe ask chatgpt
it can calculate
nah ill just do it manually, find the max power i can go without going over and then just limit it to that. thanks tho
good luck but i would not recommend using body velocity instead use linear
I have bad experience with body velocity
You can use the vertical motion under constant gravity formula:
vf^2 = vi^2 - 2gh where vf is the final velocity at the top (so 0), vi is the initial velocity (your upPower), g is the gravity and h is the max height. You can rearange it to get:
h = (u^2)/2g
Using this formula you can find out how high the character will go.
you can apply it like this:
MaxHeight = (upPower^2) / (2 * Workspace.Gravity)
(This only works if you set the other body parts to massless while being launched because they will weight the body down and make it move a bit more weirdly).