speed pick up

Non-platform specific questions.

speed pick up

Postby raminkhan » Wed Dec 21, 2011 3:33 am

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.
Last edited by raminkhan on Wed Dec 21, 2011 4:54 am, edited 1 time in total.
raminkhan
 
Posts: 63
Joined: Mon Sep 12, 2011 3:35 pm
Score: 0 Give a positive score

Re: speed pick up

Postby Hblade » Wed Dec 21, 2011 4:07 am

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: speed pick up

Postby SuperSonic » Wed Dec 21, 2011 5:12 am

@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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: speed pick up

Postby Hblade » Wed Dec 21, 2011 5:36 am

Collisions will goof with that method though wont they? :D Other than that, it's epicly short o-o
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: speed pick up

Postby foleyjo » Wed Dec 21, 2011 1:51 pm

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)
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: speed pick up

Postby SuperSonic » Wed Dec 21, 2011 2:25 pm

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
A tree never hits an automobile except in self-defence.

Want to use your joystick or controller with Game Editor? Check out my controller engine =D
User avatar
SuperSonic
 
Posts: 1443
Joined: Fri Sep 24, 2010 9:24 pm
Location: Anywhere
Score: 72 Give a positive score

Re: speed pick up

Postby Hblade » Wed Dec 21, 2011 3:19 pm

xD Yes, epic shortend code has become epically epic shorter. ?

"I've been working on my epicness XD"

xD
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest