Page 1 of 1
Code help needed.
Posted:
Sat Jul 25, 2009 5:27 pm
by Qsmash
- Code: Select all
xvelocity+=0.1;
if(xvelocity==0)
{
xvelocity=0;
}
I'm trying to make it so that my character will slow down to a complete stop, but I did something wrong...
Re: Code help needed.
Posted:
Sat Jul 25, 2009 6:12 pm
by DST
- Code: Select all
xvelocity*=0.99;
if(xvelocity<0.1){
xvelocity=0;}
will make a character slow to a stop.
Re: Code help needed.
Posted:
Sun Jul 26, 2009 2:22 am
by Qsmash
That didn't quite work. It just keeps going.
also, this for key up event.
Re: Code help needed.
Posted:
Sun Jul 26, 2009 4:06 am
by Hblade
you could try this
- Code: Select all
if (xvelocity>0)
{
xvelocity = xvelocity - .99;
}
if (xvelocity<0.01)
{
xvelocity = 0;
}
Re: Code help needed.
Posted:
Sun Jul 26, 2009 4:33 am
by skydereign
That wouldn't work either, as Qsmash is trying to put this code into the keyup event. This runs only on keyup, so it is not practical for slowing down. I would suggest using a variable to signify the keyup. This way you can put the script DST has in draw, with the variable as a condition.
Re: Code help needed.
Posted:
Sun Jul 26, 2009 7:14 am
by Fuzzy
Hblade wrote:you could try this
- Code: Select all
if (xvelocity>0)
{
xvelocity = xvelocity - .99;
}
if (xvelocity<0.01)
{
xvelocity = 0;
}
Add zeros before decimals Hblade.
0.99 not
.99. Please practice good coding, especially when giving examples to others.
Re: Code help needed.
Posted:
Sun Jul 26, 2009 1:47 pm
by DST
Cmon, fuzz, lighten up!
But seriously, the events are designed for you to change variables, not so much to actually enter code.
The main portion of your actor's events end up in DrawActor.
Re: Code help needed.
Posted:
Sun Jul 26, 2009 4:49 pm
by Qsmash
It slowed down a bit, but if leave the key down long enough it wont.
umm...here's something else I probably should've mentioned.
- Code: Select all
xvelocity+=0.1;
If you haven't noticed....I don't really understand codes to well.