FacebookTwitter
Hatrack River Forum   
my profile login | search | faq | forum home

  next oldest topic   next newest topic
» Hatrack River Forum » Active Forums » Books, Films, Food and Culture » Flash 2008 Help

   
Author Topic: Flash 2008 Help
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay I have a car and I want it to move forward, turn in either direction and when I move forward the shape moves in the direction its pointed.

How do I do this codewise.

I have a shape, I program it to turn left or right based on keypress.

And now I need it to move in the direction its pointed.

car_mc._x += Math.cos( car_mc._rotation * Math.PI/180 ) * Acceleration;
car_mc._y += Math.sin( car_mc._rotation * Math.PI/180 ) * Acceleration;

I think is the lines needed to get it done according to the teacher but it isnt working right.

Can anyone help?

IP: Logged | Report this post to a Moderator
fugu13
Member
Member # 2859

 - posted      Profile for fugu13   Email fugu13         Edit/Delete Post 
Okay, do you understand what those lines are doing? Apparently car_mc._rotation is a variable holding the rotation direction in degrees. By converting to radians (that's the * Math.PI/180 stuff), you then take the cosine (or sine) to get the part of the direction in the x (or y) direction. Having this, you multiply it by the Acceleration to find the acceleration in each direction (x and y).

I'm not sure why these acceleration numbers are then assigned to car_mc._x and car_mc._y . I would think those were positions. If those are positions, you need to do something like the following:
code:
car_mc._velocity_x += Math.cos( car_mc._rotation * Math.PI/180 ) * Acceleration

car_mc._velocity_y = Math.sin( car_mc._rotation * Math.PI/180 ) * Acceleration

car_mc._x += car_mc._velocity_x
car_mc._y += car_mc._velocity_y

That is, first you update the velocity of the car (whatever that member variable is called), then you update its position based on that velocity. Of course, all this should really be abstracted out, but whatever.
Posts: 15770 | Registered: Dec 2001  |  IP: Logged | Report this post to a Moderator
Blayne Bradley
unregistered


 - posted            Edit/Delete Post 
Okay I figured out the problem, aparently the symbol needs to be pointed in a particular direction first and then rotated to the proper direction for it to work.
IP: Logged | Report this post to a Moderator
   

   Close Topic   Feature Topic   Move Topic   Delete Topic next oldest topic   next newest topic
 - Printer-friendly view of this topic
Hop To:


Contact Us | Hatrack River Home Page

Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2