Jump to content
  • Advertisement

Archived

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

kiznore

Moving a sprite

This topic is 5291 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

Hi ya Im having trouble with moving a sprite in the direction that i wish. My sprite can rotate 360 degrees and it rotates in 10 degree intervals. My sprite has a x and y coordinate and i also have a variable that represents the angle that the sprite is at. I have been trying to use cos and sine but with no luck. Whta am i doing wrong. cos is for the x coordinate and sine is for the y - right. what other variable would i need to get it going thanks

Share this post


Link to post
Share on other sites
Advertisement
show us some code and maybe we can help
it does seem a bit odd that if u can find the x and y lengths u can''t move it...

Share this post


Link to post
Share on other sites

This is my code for moving the ship forward. The speed is just a value of 5. What else is needed to move it. I do get it moving but it only goes in a diagonal way no matter what way the ship is facing.








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
can ShipAngle be changed or is it set and never changed - it sounds like the ship''s angle could be constant throughout.

"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
The shipangle is changed when you press the arrow keys to tuen the ship. I have the ship ship turning on screen believe it or not.

Share this post


Link to post
Share on other sites
and the ship just keeps moving the same direction - like backwards and crap like that?

"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
well the ship goes diagonally down when the ship is between 10 - 180 and goes diagonally up between 180 - 360. when ur at 10 degrees it moves really slowly and the same for 350. the more you move it then the bigger jumps it takes across the screen

Share this post


Link to post
Share on other sites
ok if u dont really need to use radians, try just degrees. ive done some working and it seems that it should work as planned using degrees instead of radians. rads give very small numbers which someone else said might be rounded - could be true and giving a bad movement pattern. also they seem to calculate to wrong directions... sound familiar
in short, if u can, use degrees and try it

"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!