#### Archived

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

# 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.

## 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 on other sites
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 on other sites
Thanks for the help ,Ill give it a go

##### 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)
{

Radian = (ShipAngle * PI) / 180.0;

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

}
else
{

}

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

}

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

1. 1
Rutin
33
2. 2
3. 3
4. 4
5. 5

• 13
• 76
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632968
• Total Posts
3009585
• ### Who's Online (See full list)

There are no registered users currently online

×