I have a car that I want to make 2 separate wheels for. The wheels hae to be separate for adding code onto. Is there any way so that the car will stay in the same distance from the wheels at all times?
I know that there is a centre point on the car but maybe it is possible to add more points onto the car???
Offline
First you need the following sprites : One car and two wheels
I solved the problem by using the following code:
Stage:
<when green flag clicked>
<forever if><key[ right ]pressed?>
<broadcast[ goright
<end>
Code for: Wheel 1 , Wheel 2 and car :
<when I receive[ goright
<point in direction( 90 )
<move( 3 )steps>
<end>
This will make the car and wheels move at exactly the same speed all in the same direction. Now drag and drop the wheels into the right position and run your program.
Now all you need to do is do the same for going left (but just change the broadcast to goleft and <point in direction( 90 ) to <point in direction( -90 ).
I hope this helps.
OB6160
__________________________
See ALL my projects at: http://scratch.mit.edu/users/ob6160
See my blog at: oliverspcpages.blogspot.com
Offline
ob6160 wrote:
First you need the following sprites : One car and two wheels
I solved the problem by using the following code:
Stage:
<when green flag clicked>
<forever if><key[ right ]pressed?>
<broadcast[ goright
<end>
Code for: Wheel 1 , Wheel 2 and car :
<when I receive[ goright
<point in direction( 90 )
<move( 3 )steps>
<end>
This will make the car and wheels move at exactly the same speed all in the same direction. Now drag and drop the wheels into the right position and run your program.
Now all you need to do is do the same for going left (but just change the broadcast to goleft and <point in direction( 90 ) to <point in direction( -90 ).
I hope this helps.
OB6160
This was my first ever post on the forums
Funnily enough I was awnsering exactly the save question
Last edited by ob6160 (2010-12-09 13:09:07)
Offline
That seems good but in the game im designing the wheels will probably have to calculate the angle for which the car should face (depending on hill).
Essentially from what I understand from your code is that you are telling all 3 pieces to go in the same direction and at the same speed. This sort of code could have unpredictable results perhaps??? I was looking for more of a way that the car would fix its position directly based on the position of the wheels.
Offline
I started making a version of the old arcade game "Moon Patrol" - Never finished it, but the buggy and the three wheels are separate sprites - the wheels follow the rough terrain and the buggy itself rocks as the wheels move up and down.
Check out the parallax scrolling too
http://scratch.mit.edu/projects/Ratty1967UK/1469982
one day I may even finish the game!
Last edited by Ratty1967UK (2010-12-09 20:05:28)
Offline