i got when i press shift my character runs quicker but he does that in 0.001second how to make it like he goes from speed 3 to 6 in 5seconds
can someone help me with that ?
Create variables representing the character’s speed and acceleration rate. When the shift key is down, add the acceleration rate (scaled by Time.deltaTime) to the speed; when the shift key is not down, do the same, but subtract instead of add. Then, clamp the speed to the desired range. That should give you the effect that you’re after.
x = x + 1 * Time.deltaTime;
What’s the ‘1’ for in your example?
can you please fill something in the parts like speed1 speed2 and how to let it stop ?
Here’s how I would do it:
var MaxSpeed:float; //the maximum speed this object can get to
var Acceleration:float; //How fast this object gets to maximum speed
private var Speed:float = 0; //Current speed of this object
function Update()
{
if ( Input.GetKey(RunKey) ) //As long as the Run key (you decide what that would be) is held down, speed up until you reach maximum speed
{
if ( Speed < MaxSpeed ) //if our speed is lower the maximum speed...
{
Speed += Acceleration //...increase speed based on acceleration
}
else if ( Speed != MaxSpeed ) //else, if we passed the maximum speed
{
Speed = MaxSpeed; //limit the current speed to the value of MaxSpeed
}
}
transform.Translate(Vector3.forward * Speed, Space.Self); //move the object based on the value of Speed
}
wow it crapped up my hole game can someone maybe give me a other way to solve it ?
How did you implement it? Show me your script.
btw, here’s the code in action, I made it so my character is constantly running:
http://www.puppeteerinteractive.com/gallery/games/Swift/WIP11/
Nice game !
here is my normal script :
Thanks! Try to change this last part:
if (Input.GetButton ("Shift"))
speed = 6.0;
else
speed = 3.0;
To this:
if (Input.GetButton ("Shift"))
{
if ( speed < 6.0 )
{
speed += Acceleration;
}
}
else
{
if ( speed > 3.0 )
{
speed -= Acceleration;
}
}
Remember to give Acceleration a meaningful value, something like 0.1 or a little less depending on how long you want it to take to get to maximum speed.
uh ?!?!?
now running doesnt even work anymore
did you give a value to Acceleration?
change this:
var Acceleration:float;
to this:
var Acceleration:float = 0.1;
EDIT: Sorry my mistake, I had a typo right at the start . I wrote Accelerarion instead of Acceleration.
yes i have made it 0.1 and 0.5 and 1.0 it does not work
AWESOME MAN !!!
you rock
really really thanks for it…
if searched for it for months !
Glad to have helped. Don’t forget to show us your game in the Showcase section
@The OP: Note that Puppeteer’s code is not framerate-independent, which is not what you want in most cases. You should instead be scaling both the acceleration and the speed by Time.deltaTime (and once you add that, you’ll basically have exactly what I described in the very first reply to your thread).
i really want to do…
and i gonna do it too
but first have to make a lot more new things i just started