This site requires JavaScript, please enable it in your browser!
Greenfoot back
oNkas
oNkas wrote ...

2013/6/15

How to fallow rotation from another object "properly"

oNkas oNkas

2013/6/15

#
Hi, i'm having problem with car wheels, they have to rotate with turns. Wheel and car is difference objects. (Image Link) setRotation(car.getRotation()); It work fine... But then setLocation(car.getX() + 30, car.getY() - 15); // Left wheel Wheel have to stay like this (in pic #1) at all 0-360 degrees... When i turn, wheel location mess up and getting this (in pic #2)...
bourne bourne

2013/6/15

#
Something like this: (haven't tested it) // Left wheel setLocation( car.getX() + (int)(Math.cos(Math.toDegrees(car.getRotation())) * 30 + Math.cos(Math.toDegrees(car.getRotation() - 90)) * 15), car.getY() + (int)(Math.sin(Math.toDegrees(car.getRotation())) * 30 + Math.sin(Math.toDegrees(car.getRotation() - 90)) * 15));
danpost danpost

2013/6/15

#
Better, might be to place the wheel in this manner (this for the left front wheel):
setLocation(car.getX(). car.getY());
setRotation(car.getRotation());
turn(-90); 
move(15);
turn(90);
move(30);
oNkas oNkas

2013/6/16

#
bourne your didint work, something maybe wrong. I used what danpost sayed and it works fine, so thanks.
You need to login to post a reply.