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

velvet garnet
#

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.

rancid spindle
#

you wanna stop the player in an instant?

#

@velvet garnet

velvet garnet
rancid spindle
velvet garnet
#

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

rancid spindle
#

so what you need to do

#

first get the starting position

#

actually i dont think my calculation would work

velvet garnet
west geyserBOT
#

studio** You are now Level 8! **studio

rancid spindle
#

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

rancid spindle
#

Wait why not detect it on the client

#

maybe it might be more accurate there

velvet garnet
#

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?

rancid spindle
#

wdym

#

what is the context anyways

velvet garnet
#

wdym by context

#

wait its like 2 am and im a bit sleep deprived so i apologize if im being a dumbass rn

rancid spindle
#

like why do all of this

#

what is your goal

velvet garnet
rancid spindle
#

like set the player's velocity 0 or am i understanding this wrong

velvet garnet
#

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

rancid spindle
velvet garnet
rancid spindle
#

it can calculate

velvet garnet
rancid spindle
#

I have bad experience with body velocity

pine ether
#

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