1
\$\begingroup\$

I understand this piece of code

Enemy.position.Y = StartPosition.Y + (-(float)Math.Cos(position.X / 100) * 100);

However it only works along the X axis. What I want to be able to do is move it along an arbitrary axis; Set an angle as the x axis. How would I go about this?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

I'm not sure if I understand your question but here goes:

I think you want the sprite to wave over an angle back and forth: Not this is pseudocode (as you didn't state the language):

t=(t+wavespeed)%TwoPi;
a = Sin(t)*amplitude;  
Position.X=StartPosition.X + Cos(angle) * a;
Position.Y=StartPosition.Y + Sin(angle) * a;

t controls the waving motion; the wavespeed variable is a small value like 0.01 (note that it should slowly range from 0 to TwoPi). amplitude is the maximum you want your sprite to move, a is calculated as the amplitude for that frame. angle is the angle of the axis you want your sprite to wave along.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .