Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How to have a sprite rotate on another sprite's axis?
- -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!
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?
This was more difficult than I thought it would be!So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
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!
- Strajox
-
Scratcher
100+ 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.
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?
Your link doesn't work, did you share your project?This was more difficult than I thought it would be!So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
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?
Your link doesn't work, did you share your project?This was more difficult than I thought it would be!So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
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!
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?
The track needs to rotate on the car's axis, not the middle.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!
- gor-dee
-
Scratcher
1000+ posts
How to have a sprite rotate on another sprite's axis?
The link still isn't working and I don't see it on your profile???Your link doesn't work, did you share your project?This was more difficult than I thought it would be!So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
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!
https://scratch.mit.edu/projects/356961483/
its shared. should work
- PutneyCat
-
Scratcher
500+ 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!
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?
It says its shared. Let me reshare. If it doesn't show up I will contact the STThe link still isn't working and I don't see it on your profile???Your link doesn't work, did you share your project?This was more difficult than I thought it would be!So when I moved the code into my project, this happened https://scratch.mit.edu/projects/356961483/ how do I fix it?
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!
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?
Thank you! It works perfectly!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))
- gor-dee
-
Scratcher
1000+ posts
How to have a sprite rotate on another sprite's axis?
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)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))
- 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?
Converted my project https://scratch.mit.edu/projects/357343638/ into a race track…Ok
- Discussion Forums
- » Help with Scripts
-
» How to have a sprite rotate on another sprite's axis?