howTo "velocity max"

Non-platform specific questions.

howTo "velocity max"

Postby RippeR7420 » Mon Sep 05, 2011 4:21 am

Is there a way to to set the maximum velocity of x and/or y?
In my game when my character collides with the Top of an enemy,
I have it set to bounce him in the air.but some times it launches my
Character really high in the air... how can I limit it to a certain velocity?

My code now is just:


Enemy- collision- bottom side of player- reapeat no- script editor-
Code: Select all
player.yvelocity=player.yvelocity - 20;


Thanks to whom will help!
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: howTo "velocity max"

Postby skydereign » Mon Sep 05, 2011 4:25 am

Well, you can use this code. It uses the functions min and max, which returns the minimum or maximum of the two variables you pass it. What this does is first limit the bottom, so it can't be less than -20, then takes that velocity and says it can't be higher than 20.
Code: Select all
xvelocity=min(max(xvelocity, -20), 20);
yvelocity=min(max(yvelocity, -20),20);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: howTo "velocity max"

Postby RippeR7420 » Mon Sep 05, 2011 5:27 am

Where would I use this code at?

Under Player-> Draw Actor-> Script Editor?

or Enemy-> Collsion-> Bottom Side -> No -> Script Editor?

Thank you!!
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: howTo "velocity max"

Postby skydereign » Mon Sep 05, 2011 5:33 am

Well it depends. I'd probably write a global function out of it, and use it whenever I change the actor's velocity, but essentially you can put it in the player's draw if you want to limit the player's velocity. Or, if you don't edit the player's velocity often, you can put it into the collision event.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: howTo "velocity max"

Postby RippeR7420 » Mon Sep 05, 2011 10:22 pm

Cool :)

Thanks sky!

There's one issues with that code, the xvelocity effects my player when I jump.
Like there is wind to my back? Should I just put the code for xvelocity in the collision
With an enemy only?
CURRENT PROJECTS:

-Olo: The Sword Shaman http://game-editor.com/forum/viewtopic.php?f=4&t=12919

-The Wrath of Blob: (On the back burner)

-StickMcGee - Blast to the Future http://game-editor.com/forum/viewtopic.php?f=4&t=13660
User avatar
RippeR7420
 
Posts: 391
Joined: Mon Apr 27, 2009 4:16 pm
Location: Salt Lake City, Utah.
Score: 23 Give a positive score

Re: howTo "velocity max"

Postby skydereign » Mon Sep 05, 2011 11:47 pm

If you don't need the xvelocity part, don't add it. You can also change the limits by changing the -20 and the 20. Do you understand how the code works? If you really do understand, then you should know where to put it and how to work with it.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest