PDA

View Full Version : Projecting Vectors to the Axis



Tamamo
11-13-2015, 02:12 PM
Okay so I'm trying to figure out how to make a enemy move in a parabola along the Z axis while moving along x and y in a a straight lineon the other Axis.
In otherwords it swoops down from variables x and y too a and b (the midpoint of the line) and fires then swoops back up until it reaches endx and endy.
The problem I'm having is Projecting the vector to the X axis.


void Swoop(ffc this, npc ghost, bool numSweeps)
{
float a=Link->X;
float b=Link->Y;
float x=Ghost_X;
float y=Ghost_Y;
float endx=GetEndX(x);
float endy=GetEndY(y);
float angle=Angle(x,y,endx,endy); //Axis Angle
int counter=0;

//Descend
while(counter<TBIRD_SWEEP_TIME && Ghost_HP>0)
{
counter++;
Ghost_X=SmoothStep(x,a,counter/TBIRD_SWEEP_TIME);
Ghost_Y=SmoothStep(y,b,counter/TBIRD_SWEEP_TIME);
//Vector Projection

TBird_Waitframe(this,ghost);
}

//Fire
if(numSweeps==1 && (ghost->Attributes[TBIRD_ATTRIBUTES_FLAGS] & TBIRD_NO_SBOLT)==0)
SBolt(this, ghost);
else
Fire(this, ghost);

//Ascend
}

Asuna Yuuki Nagato
03-08-2024, 06:19 PM
The vector dot product is your friend.