how to get distance plus distance traveled

id: 751266

category: Help with Scripts

posts: 19

a sprite in my game will travel to a point on the map, how can i get its distance traveled, and the total distance from point A to B, into two variables
i think i figured out
https://scratch.mit.edu/projects/992294177/
check this out
and ask me if you have any question
so the distance traveled thing is all good, but when i said total distance i mean like the distance inbetween point a and b
What is the feature that will use this? Don't get caught up in the x y problem. However, you can try this:

In point A
(distance to [point b v])
will give you the distance from point a to point b.

In the sprite that should move,
(distance to [point a v])
will give you how far the sprite has traveled.

HOWEVER, I guarantee that there is a better solution to your problem than using these blocks/this method.

rendered_fox1 wrote:

so the distance traveled thing is all good, but when i said total distance i mean like the distance inbetween point a and b[/quoi me

rendered_fox1 wrote:

so the distance traveled thing is all good, but when i said total distance i mean like the distance inbetween point a and b

i mean isnt the distance between point A and B just distance traveled?
that shows the distance for each time you move

MrKingofScratch wrote:

What is the feature that will use this? Don't get caught up in the x y problem. However, you can try this:

In point A
(distance to [point b v])
will give you the distance from point a to point b.

In the sprite that should move,
(distance to [point a v])
will give you how far the sprite has traveled.

HOWEVER, I guarantee that there is a better solution to your problem than using these blocks/this method.
to use “distance to ()” block you just need another sprite to find the distance
bruh i completley forgot that block existed thanks guys
For finding the distance between two points you can use the distance formula. This should work for both finding the distance between the two points but also the distance the sprite has traveled.


PS: once again make sure you're not running into the x y problem
ok so i made the code block but it wont change the size of it at all

also i made an object go to the landing spot and make a variable that is the total distance from a to b

heres the code i made:
im not good with these scratchblocks btw

set size to ((([sin v] of ((((distance to [player v])::#6f6f6f) * (90)) / (total distance::#6f6f6f))) * (125)) + (75)) %
There's a limit to how small or large a sprite can be. The solution depends on if you want to make it bigger or smaller.

PS: hit the green checkmark when writing a post to preview what the scratchblocks will look like

MrKingofScratch wrote:

There's a limit to how small or large a sprite can be. The solution depends on if you want to make it bigger or smaller.

PS: hit the green checkmark when writing a post to preview what the scratchblocks will look like

both?? its just growing to 200 until it hits the midpoint then shrinks to 75
What do you want it to do- grow as it goes to point b? If so, that sin block is messing it up.

MrKingofScratch wrote:

What do you want it to do- grow as it goes to point b? If so, that sin block is messing it up.

grow as it goes to point b, but shrinks after hitting the midpoint of its travel line
removed bc it was not what you wanted… working on it rn
thanks, & how can i customize this and cap the size
it only grew and didnt shrink, for some reason i switched it to floor and it does shrink now, but it starts too small and its peak is also too small, how do i make it so it starts on 75% size
You switched what to floor?

also if you're using my project, add 75 to the size, and instead of multiplying the size by 100, multiply it by 25. This will make it so that the distance affects a range from 0 to 25, and adding 75 makes it so it starts at 75. If you want me to do this let me know.