This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-10-10 06:37:54

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

Attaching wheels to a car???

Hi everyone!

Im making a side-view scroller with a car. I want to have the 2 wheels separate sprites from the car but still attached to the car so I can add more realistic physics to the car.

How can I do this?

Offline

 

#2 2010-10-10 06:43:18

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: Attaching wheels to a car???

A. This does not belong here
B. You need to be prepared to use trigonometry
C. Make 2 sprites for the wheels and make them turn
D. Use trig functions to set the position of the two wheels according to direction of car.

Offline

 

#3 2010-10-10 07:25:35

colorfusion
Scratcher
Registered: 2009-10-03
Posts: 500+

Re: Attaching wheels to a car???

Just make 2 sprites for the wheels, then make each of them go to the y and x position of the car, minus or plus a certain amount depending on how big the car is and where the sprite centre is.

Offline

 

#4 2010-10-10 09:32:27

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Attaching wheels to a car???

It really depends: will the car be rotating? If so, you'll need to do some tricks with Trigonometry. Otherwise, follow colorfusion's advice.

Offline

 

#5 2010-10-11 12:32:57

rep353
Scratcher
Registered: 2010-03-22
Posts: 40

Re: Attaching wheels to a car???

coolstuff wrote:

It really depends: will the car be rotating? If so, you'll need to do some tricks with Trigonometry. Otherwise, follow colorfusion's advice.

I'm not too put off by the trigonometry, I think it could be interesting to apply my knowledge from maths class. I hope to apply rotation and possibly even suspension to the car so trigonometry is probably the way to go. If there are any examples of trigonometry applied to a scratch program could you please post them here.

Offline

 

#6 2010-10-11 12:50:08

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Attaching wheels to a car???

There are plenty of examples of Trigonometry being applied to a Scratch program, actually. Perhaps what you're looking for is Paddle2See's demonstration of a Motorcycle... It's probably most similar to what you're looking for.

Offline

 

#7 2010-10-12 06:05:20

ob6160
Scratcher
Registered: 2010-10-10
Posts: 500+

Re: Attaching wheels to a car???

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


http://i45.tinypic.com/2jcygsy.gif

Offline

 

#8 2010-10-12 07:27:42

coolstuff
Community Moderator
Registered: 2008-03-06
Posts: 1000+

Re: Attaching wheels to a car???

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

__________________________

See ALL my projects at: http://scratch.mit.edu/users/ob6160
See my blog at: oliverspcpages.blogspot.com[/blocks]

Interesting solution! However, I don't believe it'll work if the car needs to rotate, which is why Trigonometry is the answer  wink

Offline

 

Board footer