#define MaxSpeed 10
#define IncrementSpeed 0.5
int Dir = 0;//The direction that sonic is moving in. 1 for right, -1 for left, and 0 for stopped.
Dir = 1;//moving left
Dir = -1;//moving right
Dir = 0;//stopped
if(Dir == 1)
{
if(xvelocity < MaxSpeed)//If sonic is not going as fast as he can...
{
xvelocity += IncrementSpeed;//...then speed him up.
//You can also put animation code here ;)
}
}
else if(Dir == -1)
{
if(xvelocity > MaxSpeed)
{
xvelocity -= IncrementSpeed;//This will also speed him up. But in the opposite direction :D
//Again, you can put animation code here
}
}
else//If Dir is not equal to 1 or -1, then it must be equal to 0
{
if(xvelocity > 0)
{
xvelocity -= IncrementSpeed;
}
else if(xvelocity < 0)
{
xvelocity += IncrementSpeed;
}
}
double xvel = xvelocity;
PhysicalResponse(MOVE_EVENT_ACTOR_ONLY, USE_CALCULATED_MASS, 1.000000,1.000000, 0.000000, 0.000000);
xvelocity = xvel;
CrimsonTheDarkBat wrote:Thanks dude it works mostly
However only in one direction :/ Sonic can only move right correctly - left dosent budge one bit ^^;
Also, when Sonic collides with different section of the floor (separate floor actor) he stops slightly :/ any more ideas? ^^;
if(Dir == 1)
{
if(xvelocity < MaxSpeed)//If sonic is not going as fast as he can...
{
xvelocity += IncrementSpeed;//...then speed him up.
//You can also put animation code here ;)
}
}
else if(Dir == -1)
{
if(xvelocity > -MaxSpeed)
{
xvelocity -= IncrementSpeed;//This will also speed him up. But in the opposite direction :D
//Again, you can put animation code here
}
}
else//If Dir is not equal to 1 or -1, then it must be equal to 0
{
if(xvelocity > 0)
{
xvelocity -= IncrementSpeed;
}
else if(xvelocity < 0)
{
xvelocity += IncrementSpeed;
}
}
CrimsonTheDarkBat wrote:Well basically I've got the player actor moving correctly using the code above, but when he collides with a separate floor actor (eg; moving from a flat piece of land to a sloped piece of land) then he stops and starts moving again as though the player depressed the key and pressed it again. All collisions in the game use the code skydereign mentioned above.
Users browsing this forum: No registered users and 1 guest