is velocity max or limit or range possible?

Talk about making games.

is velocity max or limit or range possible?

Postby stevenp » Tue Dec 25, 2007 6:24 pm

is velocity max or limit or range possible? cuz i make my guy walk, and he just keeps gettign faster and faster
User avatar
stevenp
 
Posts: 403
Joined: Sat Dec 22, 2007 12:49 pm
Location: canada, ontario
Score: 16 Give a positive score

Re: is velocity max or limit or range possible?

Postby Troodon » Tue Dec 25, 2007 8:41 pm

if (xvelocity > 10)
{
xvelocity = 10;
}
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Re: is velocity max or limit or range possible?

Postby Fuzzy » Wed Dec 26, 2007 8:44 am

Code: Select all
xvelocity = xvelocity % 10;


That is all you need.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: is velocity max or limit or range possible?

Postby Troodon » Wed Dec 26, 2007 10:04 am

Fuzzy wrote:
Code: Select all
xvelocity = xvelocity % 10;


That is all you need.


Wow I haven't seen that used in this case before! :D
What's the % doing? Earlier I tought it was temporary var. :|
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Re: is velocity max or limit or range possible?

Postby Fuzzy » Wed Dec 26, 2007 11:21 am

Its the MOD operator. it divides var by 10 and chucks the quotient away and keeps the remainder. since the remainder has to be between 0 and 10, you get the range you want.

Actually I should have said
Code: Select all
xvelocity = xvelocity % 11;


If you are willing to restrict to certain values you can do it another way.

Code: Select all
xvelocity = xvelocity & 8;


1,2,4,8,16,32... is the sequence. Its even faster than %.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: is velocity max or limit or range possible?

Postby j2graves » Wed Dec 26, 2007 12:08 pm

Interesting
No games to my name...
User avatar
j2graves
 
Posts: 1302
Joined: Thu Aug 16, 2007 6:42 pm
Location: on the other side of infinity
Score: 19 Give a positive score

Re: is velocity max or limit or range possible?

Postby Troodon » Thu Dec 27, 2007 8:48 am

Fuzzy wrote:Its the MOD operator. it divides var by 10 and chucks the quotient away and keeps the remainder. since the remainder has to be between 0 and 10, you get the range you want.

Actually I should have said
Code: Select all
xvelocity = xvelocity % 11;


If you are willing to restrict to certain values you can do it another way.

Code: Select all
xvelocity = xvelocity & 8;


1,2,4,8,16,32... is the sequence. Its even faster than %.


Nice, here's a score. :)
I can't die, I already tried
~on the forums since GE 1.3.3~
User avatar
Troodon
 
Posts: 1539
Joined: Thu Jan 12, 2006 3:29 pm
Location: HELL
Score: 56 Give a positive score

Re: is velocity max or limit or range possible?

Postby Fuzzy » Fri Dec 28, 2007 2:00 pm

Thank you for the point!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: is velocity max or limit or range possible?

Postby Bee-Ant » Fri Dec 28, 2007 2:06 pm

So % and &...also...
I'll try :D
Btw, how long you work with code stuff Pete?
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: is velocity max or limit or range possible?

Postby Fuzzy » Fri Dec 28, 2007 2:24 pm

2 days!
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: is velocity max or limit or range possible?

Postby Bee-Ant » Fri Dec 28, 2007 2:32 pm

Dont make a stupid joke :lol:
Btw, do you have another idea to solve my problem in "SENIOR I NEED HELP" topic in this Game Development Sub forum??? :mrgreen:
User avatar
Bee-Ant
 
Posts: 3723
Joined: Wed Apr 11, 2007 12:05 pm
Location: http://www.instagram.com/bee_ant
Score: 210 Give a positive score

Re: is velocity max or limit or range possible?

Postby mrzee001 » Mon Dec 31, 2007 5:39 pm

Trying fuzzy's approach to ristrict the velocity to a certain limit,
xvelocity -= xvelocity % 11;
I keep getting an error msg : "illigal binary operation to ' % ' "
any idea why?
thanks
mrzee001
 
Posts: 3
Joined: Sun Oct 28, 2007 6:56 am
Score: 0 Give a positive score

Re: is velocity max or limit or range possible?

Postby Fuzzy » Mon Dec 31, 2007 9:17 pm

its because xvelocity(and most of the actor movement variables) are real or float values. You need to type cast to an integer.
Code: Select all
xvelocity -= (int)xvelocity % 11;


should work.

Type casting means that you tell GE(or C/C++) to temporarily consider that variable to be an integer. Certain operations like % and & only work with integers.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: is velocity max or limit or range possible?

Postby mrzee001 » Tue Jan 01, 2008 10:53 pm

that was the problem, so thank you for the tip.
mrzee001
 
Posts: 3
Joined: Sun Oct 28, 2007 6:56 am
Score: 0 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron