Discuss Scratch

-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

I am making a racing game. When I hit the left or right arrow keys, I want the entire track to turn, not the car. So basically the sprite would rotate but on another sprite's axis. Sorry if you are confused - It's a weird question.

Last edited by -cooleddie001- (Jan. 6, 2020 02:24:22)

gor-dee_test
Scratcher
100+ posts

How to have a sprite rotate on another sprite's axis?

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
Strajox
Scratcher
100+ posts

How to have a sprite rotate on another sprite's axis?

-cooleddie001- wrote:

I am making a racing game. When I hit the left or right arrow keys, I want the entire track to turn, not the car. So basically the sprite would rotate but on another sprite's axis. Sorry if you are confused - It's a weird question.

You could put this into your track sprite:

when green flag clicked
forever
if <key [left arrow] pressed?> then
turn ccw (amount of degrees you want to turn. make sure it is turning to the right and not left) degrees
end
if <key [right arrow] pressed?> then
turn cw (amount of degrees you want to turn. make sure it is turning to the left and not right) degrees
end
end

And also make the car stay in place. Hope this helped!

Last edited by Strajox (Jan. 6, 2020 19:57:21)

gor-dee_test
Scratcher
100+ posts

How to have a sprite rotate on another sprite's axis?

-cooleddie001- wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
Your link doesn't work, did you share your project?
-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

gor-dee_test wrote:

-cooleddie001- wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
Your link doesn't work, did you share your project?

https://scratch.mit.edu/projects/356961483/
its shared. should work
-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

Strajox wrote:

-cooleddie001- wrote:

I am making a racing game. When I hit the left or right arrow keys, I want the entire track to turn, not the car. So basically the sprite would rotate but on another sprite's axis. Sorry if you are confused - It's a weird question.

You could put this into your track sprite:

when green flag clicked
forever
if <key [left arrow] pressed?> then
turn ccw (amount of degrees you want to turn. make sure it is turning to the right and not left) degrees
end
if <key [right arrow] pressed?> then
turn cw (amount of degrees you want to turn. make sure it is turning to the left and not right) degrees
end
end

And also make the car stay in place. Hope this helped!
The track needs to rotate on the car's axis, not the middle.
gor-dee
Scratcher
1000+ posts

How to have a sprite rotate on another sprite's axis?

-cooleddie001- wrote:

gor-dee_test wrote:

-cooleddie001- wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
Your link doesn't work, did you share your project?

https://scratch.mit.edu/projects/356961483/
its shared. should work
The link still isn't working and I don't see it on your profile???
PutneyCat
Scratcher
500+ posts

How to have a sprite rotate on another sprite's axis?

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!

I've also struggled with this before. It took me a while to rediscover a way of doing it without using the trig operators. FWIW I think this works (as an adapted version of your “turn” script):

set [stored distance v] to (distance to [ball v])
set [original direction v] to (direction)
point towards [ball v]
go to [ball v]
turn cw (degrees) degrees
move (() - (stored distance)) steps
point in direction ((original direction) + (degrees))

Last edited by PutneyCat (Jan. 7, 2020 11:23:24)

-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

gor-dee wrote:

-cooleddie001- wrote:

gor-dee_test wrote:

-cooleddie001- wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!
So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
Your link doesn't work, did you share your project?

https://scratch.mit.edu/projects/356961483/
its shared. should work
The link still isn't working and I don't see it on your profile???
It says its shared. Let me reshare. If it doesn't show up I will contact the ST
-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

PutneyCat wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!

I've also struggled with this before. It took me a while to rediscover a way of doing it without using the trig operators. FWIW I think this works (as an adapted version of your “turn” script):

set [stored distance v] to (distance to [ball v])
set [original direction v] to (direction)
point towards [ball v]
go to [ball v]
turn cw (degrees) degrees
move (() - (stored distance)) steps
point in direction ((original direction) + (degrees))
Thank you! It works perfectly!
gor-dee
Scratcher
1000+ posts

How to have a sprite rotate on another sprite's axis?

PutneyCat wrote:

gor-dee_test wrote:

This was more difficult than I thought it would be!
https://scratch.mit.edu/projects/357343638/
I'm not sure if my solution is the most efficient way to do this but it does work!

I've also struggled with this before. It took me a while to rediscover a way of doing it without using the trig operators. FWIW I think this works (as an adapted version of your “turn” script):

set [stored distance v] to (distance to [ball v])
set [original direction v] to (direction)
point towards [ball v]
go to [ball v]
turn cw (degrees) degrees
move (() - (stored distance)) steps
point in direction ((original direction) + (degrees))
I had a feeling something like this was doable but I couldn't get it to work (I wasn't doing the point towards ball at the beginning)
gor-dee_test
Scratcher
100+ posts

How to have a sprite rotate on another sprite's axis?

Converted my project https://scratch.mit.edu/projects/357343638/ into a race track…
-cooleddie001-
Scratcher
29 posts

How to have a sprite rotate on another sprite's axis?

gor-dee_test wrote:

Converted my project https://scratch.mit.edu/projects/357343638/ into a race track…
Ok

Powered by DjangoBB