Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Getting the center position of a rotated sprite sprite
- griffithsrock1
-
39 posts
Getting the center position of a rotated sprite sprite
I have a question. I have a project which has a car with some car physics and stuff.
The back tire has gravity on it, the body of the car is locked to the back tire, and the front tire is locked to the body.
The body can rotate, and so can the front tire, offset from the scratch origin, so that the front tire is always where it should be.
The only issue is that, I want the tires to both rotate. The back tire is already centered on the origin, so it can rotate. But the other tire is not centered at the origin and it uses rotation to stick to the body, and for some calculations.
I want it so that the front tire can rotate, using another sprite that is centered. But I need to somehow find out where the center of the front tire sprite is, not based on the origin, but on the graphic.
How could I do this?
Project Source: https://scratch.mit.edu/projects/977894216/

The back tire has gravity on it, the body of the car is locked to the back tire, and the front tire is locked to the body.
The body can rotate, and so can the front tire, offset from the scratch origin, so that the front tire is always where it should be.
The only issue is that, I want the tires to both rotate. The back tire is already centered on the origin, so it can rotate. But the other tire is not centered at the origin and it uses rotation to stick to the body, and for some calculations.
I want it so that the front tire can rotate, using another sprite that is centered. But I need to somehow find out where the center of the front tire sprite is, not based on the origin, but on the graphic.
How could I do this?
Project Source: https://scratch.mit.edu/projects/977894216/

Last edited by griffithsrock1 (March 15, 2024 17:26:37)
- BigNate469
-
1000+ posts
Getting the center position of a rotated sprite sprite
Trial and error to find the offset. Keep in mind that 1 pixel on the stage = 1 pixel in the drawing editor, assuming the size is set to 100%.
Then, just use a move block after you apply direction.
EDIT: you can scale the position by size if you need to.
Then, just use a move block after you apply direction.
EDIT: you can scale the position by size if you need to.
Last edited by BigNate469 (March 15, 2024 17:11:27)
- griffithsrock1
-
39 posts
Getting the center position of a rotated sprite sprite
Trial and error to find the offset. Keep in mind that 1 pixel on the stage = 1 pixel in the drawing editor, assuming the size is set to 100%.
Then, just use a move block after you apply direction.
EDIT: you can scale the position by size if you need to.
I'm not 100% sure what you are saying, but what I need is an equation, because the project is doing some heavy rendering already, which means I don't have a lot of memory to spare. It needs to be a super fast calculation.
- BigNate469
-
1000+ posts
Getting the center position of a rotated sprite sprite
set your front wheel's x-position to:Trial and error to find the offset. Keep in mind that 1 pixel on the stage = 1 pixel in the drawing editor, assuming the size is set to 100%.
Then, just use a move block after you apply direction.
EDIT: you can scale the position by size if you need to.
I'm not 100% sure what you are saying, but what I need is an equation, because the project is doing some heavy rendering already, which means I don't have a lot of memory to spare. It needs to be a super fast calculation.
- griffithsrock1
-
39 posts
Getting the center position of a rotated sprite sprite
set your front wheel's x-position to:Trial and error to find the offset. Keep in mind that 1 pixel on the stage = 1 pixel in the drawing editor, assuming the size is set to 100%.
Then, just use a move block after you apply direction.
EDIT: you can scale the position by size if you need to.
I'm not 100% sure what you are saying, but what I need is an equation, because the project is doing some heavy rendering already, which means I don't have a lot of memory to spare. It needs to be a super fast calculation.
Well, doing that would mean the inverse of what I need, which is calculating where it would need to be with x, and y instead of offset rotation.
- BigNate469
-
1000+ posts
Getting the center position of a rotated sprite sprite
That doesn't calculate any rotation- it calculates the x-position of the car and adds a value to it to make the value of that equation the x-position of where the wheel should be. You can rotate it afterwards, assuming that the wheel costume is centered.
You can do the same thing with the y-position.
You can do the same thing with the y-position.
- hranart1
-
31 posts
Getting the center position of a rotated sprite sprite
you can center wheel on the front axel without using rotation so you can turn the wheel easily
here is the code
here is the code
- griffithsrock1
-
39 posts
Getting the center position of a rotated sprite sprite
That doesn't calculate any rotation- it calculates the x-position of the car and adds a value to it to make the value of that equation the x-position of where the wheel should be. You can rotate it afterwards, assuming that the wheel costume is centered.
You can do the same thing with the y-position.
The wheel can be set to an x position of the car+somevalue but that is still not the right position, because of the car's rotation. I would need some way of calculating exactly what x and y position corresponds to the place where the front tire should be on the rotated car.
- griffithsrock1
-
39 posts
Getting the center position of a rotated sprite sprite
you can center wheel on the front axel without using rotation so you can turn the wheel easily
here is the code
Trigonometry saves the day! I'm not well versed in trig, so that is why I have these kinds of problems. Thank you!
- Discussion Forums
- » Help with Scripts
-
» Getting the center position of a rotated sprite sprite