Page 1 of 1

yvel

PostPosted: Mon Jun 03, 2013 7:38 am
by ESL
What is the purpose of a statement like yvelocity=yvel? It seems to be stating the obvious.

Re: yvel

PostPosted: Mon Jun 03, 2013 7:42 am
by skydereign
I assume you came across this in a collision event. yvel is not a built in variable, it stores a value.
Code: Select all
double yvel = yvelocity; // this creates a variable that remembers the value of yvelocity at this point
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0.0, 0.0);
// this call to PhysicalResponse will set yvelocity and xvelocity to 0
// note though that yvel is not set equal to 0, as it still holds the value it had at the first line

yvelocity = yvel; // this now sets yvelocity back to what it was before the collision

The reason you do that is to prevent the player from sticking to the wall. Normally after PhysicalResponse, the xvelocity and yvelocity variables are set to 0, which stops movement. In cases where you use that (collisions with walls) we only want to stop the xvelocity.