Page 1 of 1

is velocity max or limit or range possible?

PostPosted: Tue Dec 25, 2007 6:24 pm
by stevenp
is velocity max or limit or range possible? cuz i make my guy walk, and he just keeps gettign faster and faster

Re: is velocity max or limit or range possible?

PostPosted: Tue Dec 25, 2007 8:41 pm
by Troodon
if (xvelocity > 10)
{
xvelocity = 10;
}

Re: is velocity max or limit or range possible?

PostPosted: Wed Dec 26, 2007 8:44 am
by Fuzzy
Code: Select all
xvelocity = xvelocity % 10;


That is all you need.

Re: is velocity max or limit or range possible?

PostPosted: Wed Dec 26, 2007 10:04 am
by Troodon
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. :|

Re: is velocity max or limit or range possible?

PostPosted: Wed Dec 26, 2007 11:21 am
by Fuzzy
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 %.

Re: is velocity max or limit or range possible?

PostPosted: Wed Dec 26, 2007 12:08 pm
by j2graves
Interesting

Re: is velocity max or limit or range possible?

PostPosted: Thu Dec 27, 2007 8:48 am
by Troodon
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. :)

Re: is velocity max or limit or range possible?

PostPosted: Fri Dec 28, 2007 2:00 pm
by Fuzzy
Thank you for the point!

Re: is velocity max or limit or range possible?

PostPosted: Fri Dec 28, 2007 2:06 pm
by Bee-Ant
So % and &...also...
I'll try :D
Btw, how long you work with code stuff Pete?

Re: is velocity max or limit or range possible?

PostPosted: Fri Dec 28, 2007 2:24 pm
by Fuzzy
2 days!

Re: is velocity max or limit or range possible?

PostPosted: Fri Dec 28, 2007 2:32 pm
by Bee-Ant
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:

Re: is velocity max or limit or range possible?

PostPosted: Mon Dec 31, 2007 5:39 pm
by mrzee001
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

Re: is velocity max or limit or range possible?

PostPosted: Mon Dec 31, 2007 9:17 pm
by Fuzzy
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.

Re: is velocity max or limit or range possible?

PostPosted: Tue Jan 01, 2008 10:53 pm
by mrzee001
that was the problem, so thank you for the tip.