• ### What is your GameDev Story?

#### Archived

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

# Moving a sprite

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

## 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 on other sites
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 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)
{

Radian = (ShipAngle * PI) / 180.0;

if((ShipAngle >= 0) && (ShipAngle <= 180))
{

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

}

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

}

##### 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 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 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 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 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 on other sites
It''s been a while since I''ve done this, but try only:

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

without all the Ifs and stuff. Let me know if it works.

Stay Clausal,

Red Sodium

##### Share on other sites
(Sorry, posted twice, ignore this post)

[edited by - red_sodium on April 15, 2004 10:17:50 AM]

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 16
• 14
• 10
• 9
• 11
• ### Forum Statistics

• Total Topics
634094
• Total Posts
3015497
×