Discuss Scratch

rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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
invalidaccess
Scratcher
88 posts

how to get distance plus distance traveled

i think i figured out
https://scratch.mit.edu/projects/992294177/
check this out
and ask me if you have any question
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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

how to get distance plus distance traveled

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.

Last edited by kaj (Tomorrow 00:00:00)
100th post!
invalidaccess
Scratcher
88 posts

how to get distance plus distance traveled

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
invalidaccess
Scratcher
88 posts

how to get distance plus distance traveled

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
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

bruh i completley forgot that block existed thanks guys
MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

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

Last edited by kaj (Tomorrow 00:00:00)
100th post!
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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

Last edited by rendered_fox1 (March 30, 2024 20:41:52)

MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

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

Last edited by MrKingofScratch (March 30, 2024 20:43:58)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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
MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

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

Last edited by kaj (Tomorrow 00:00:00)
100th post!
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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

Last edited by rendered_fox1 (March 30, 2024 20:49:59)

MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

removed bc it was not what you wanted… working on it rn

Last edited by MrKingofScratch (March 30, 2024 21:09:09)


Last edited by kaj (Tomorrow 00:00:00)
100th post!
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

ok

Last edited by rendered_fox1 (March 30, 2024 20:53:48)

MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

here you go! https://scratch.mit.edu/projects/992320503/

Last edited by kaj (Tomorrow 00:00:00)
100th post!
rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

thanks, & how can i customize this and cap the size

Last edited by rendered_fox1 (March 30, 2024 21:11:47)

rendered_fox1
Scratcher
19 posts

how to get distance plus distance traveled

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

Last edited by rendered_fox1 (March 30, 2024 21:36:18)

MrKingofScratch
Scratcher
100+ posts

how to get distance plus distance traveled

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.

Last edited by MrKingofScratch (March 30, 2024 22:02:36)


Last edited by kaj (Tomorrow 00:00:00)
100th post!

Powered by DjangoBB