Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kiznore

need help moving sprite

This topic is 5302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

still need help moving sprite. feeling kinda stupid now. my sprite can rotate 360 degrees at 10 degree intervals. i have a xpos and ypos of my sprite. wht i want to know is how to move my sprite in the direction it is pointing. i know u use cos and sin but how. ive been trying for ages buit with no luck

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
sin and cos are trigonometry functiosn that relate to an angle. The cos of the angle is the distance on the x axis, between -1 and 1 for the angle, and sin is the y. The sin gives positive y for degrees 0 to 180 and negative for 180 to 360 to you might want to invert that depending on your coordinate system. If you''re using c or java, the angle must be in radians, between 0 and 2pi. Get the sin and cos for the angle of movement and increment the x and y positions based on those numbers times a speed value. Presto, moving at an angle. Hope this helps. Cheers!

Share this post


Link to post
Share on other sites
Still having no luck. The ship moves in a diagonal direction right and left. If the sprite is is at an angle between 0 to 180 then it goes in a diagonal direction to the right and vice versa. Below is the code im using

void cShip::ThrustShip(float speed)
{

double Radian;

Radian = (ShipAngle * PI) / 180.0;

if((ShipAngle >= 0) && (ShipAngle <= 180))
{
VelX = cos(Radian);
VelY = sin(Radian);

}
else
{
VelX = cos(Radian);
VelY = sin(Radian) * -1;

}

XPos = XPos + (VelX * speed);
YPos = YPos + (VelY * speed);


}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
That''s weird. It appears to be correct. The only reason i can think of is the distance between active (x,y), and new (x,y) pair after the speed is applied is close to 1 pixel. Or small enough such that the new (x1,y2) coordinate would be diagonal relative to the (x1,y1) coordinate. ie: 1 up 1 left, or 1 up 1 right, or the same for downward.

eg: The results after roundind off (VelX*Speed), and (VelY*Speed)are the same for both. The closer the angle to vertical, or horizontal plane, the less of a chance that this should happen.

What is the average value used for the speed parameter? Or, what is the min, and max value allowed for speed?

Share this post


Link to post
Share on other sites
I have only got speed set to 5. thats 5 pixels right. Excuse me if im wrong because im very new to game programming. The new (x,y) that your on about is my VelX and Vely(is that right).
This is really bugging me now

Share this post


Link to post
Share on other sites
i completely understand how frustrating it can be when u cant figure out what is wrong in ur code or if u cant figure out a way of making something work... i get that feeling often because it looks like it will work but doesn''t cause of some other crap that i forgot to change (thats why my current game isnt finished... i can only handle so much annoyance in one day )

"Did you hear the one about the nun and the rabbi?"
JUST PRINT (typed)
"Okay, okay, Asshole!!" - Wrongfully Accused

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!