Page 1 of 1

speed pick up

PostPosted: Wed Dec 21, 2011 3:33 am
by raminkhan
hey guys how can I increase speed on my character, okay at first the xvelocity=2; right? then I want it to pick up speed.

let me clearify that this is not my actor its my enemy on the screen which I want it to pick up speed.

Re: speed pick up

PostPosted: Wed Dec 21, 2011 4:07 am
by Hblade
put this in global code
Code: Select all
#define MaxSpeed 5 //Max Speed
#define RIGHT 0
#define LEFT 0
double SPEED; //Max speed

void
Gain(int d) //d is direction
{
    switch(d)
    {
        case 0: //Right
        if(SPEED<MaxSpeed) // if speed is less than max speed
        {
            SPEED+=.25;
        }
        x+=SPEED;
        break;
        case 1: // Left
        if(SPEED>(-MaxSpeed)) // If it's less than -maxspeed
        {
            SPEED-=.25;
        }
        x-=SPEED;
        break;
        }
}


Now in your keydown event, example:
Key Down - Right Key - Script Editor
you would put this code :3
Code: Select all
Gain(0);

then in Left Key
Code: Select all
Gain(1);


Hope this helped :3

Re: speed pick up

PostPosted: Wed Dec 21, 2011 5:12 am
by SuperSonic
@Hblade: Your method is awsome but it might not be very newb freindly. Here is how I would do it :)

Global Code:
Code: Select all
#define maxspeed 10
float speed = 0.5;//You can replace 0.5 and 10 with any other numbers you like ;)


Key Down -> Right -> Script Editor:
Code: Select all
if(xvelocity < maxspeed)
{
    xvelocity += abs(speed);
}


Key Down -> Left-> Script Editor:
Code: Select all
if(xvelocity < -maxspeed)
{
    xvelocity -= abs(speed);
}


Now of course, there would be a couple of bugs but I think that they would be pretty easy to fix :D

Re: speed pick up

PostPosted: Wed Dec 21, 2011 5:36 am
by Hblade
Collisions will goof with that method though wont they? :D Other than that, it's epicly short o-o

Re: speed pick up

PostPosted: Wed Dec 21, 2011 1:51 pm
by foleyjo
I'm a bit unsure if you are both correct or both wrong.

raminkhan said this is for the enemy so I'm guessing it is not dependent on key presses and direction isn't a factor also.

If I'm right I would go for simple timer method.

Create a repeating timer and in the OnTimer code put

xvelocity = min(xvelocity+1,maxspeed)

Re: speed pick up

PostPosted: Wed Dec 21, 2011 2:25 pm
by SuperSonic
Hblade wrote:Collisions will goof with that method though wont they? :D

I actually havn't used that method before so I'm not quite sure XD. But I think you are right because I heard people saying things about how it messed up their collision :D
Hblade wrote:Other than that, it's epicly short o-o

Thanks :P
I've been working on my epicness XD
foleyjo wrote:raminkhan said this is for the enemy so I'm guessing it is not dependent on key presses and direction isn't a factor also.

Oh woops, I must have misread his post :o

foleyjo wrote:Create a repeating timer and in the OnTimer code put

xvelocity = min(xvelocity+1,maxspeed)

That's epicly epicer than my code XD

Re: speed pick up

PostPosted: Wed Dec 21, 2011 3:19 pm
by Hblade
xD Yes, epic shortend code has become epically epic shorter. ?

"I've been working on my epicness XD"

xD