Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Forcing the player to walk
Apjjm Offline
Is easy to say

Posts: 496
Threads: 18
Joined: Apr 2011
Reputation: 52
#8
RE: Forcing the player to walk

Removing the timer may not always work for fast timers, as by the time the collision callback has been triggered, the timer may have expired and the callback event queued up ready to be called - at least if i recall correctly. A just as simple and more robust solution is to use a variable to track whether or not to renew the timer. E.g.
//Start walking forward
void StartWalking(float afAmount)
{
    SetLocalVarFloat("WalkAmount",afAmount);
    cbWalkTimer("WalkTimer");
}

//Stop walking forward
void StopWalking()
{
    SetLocalVarFloat("WalkAmount",0);
}

//Timestep - this constant is the delay between timer calls
const float TIMESTEP = 1.0f / 60.0f;
void cbWalkTimer(string &in asTimer)
{
    //Get step amount -> if 0 then walking has stopped
    float walkamt = GetLocalVarFloat("WalkAmount");
    if(walkamt == 0) return;
    //Else step forward and add timer so that you can walk forward again next frame
    MovePlayerForward(walkamt);
    AddTimer(asTimer,TIMESTEP,"cbWalkTimer");
}
In the above code I have encapsulated the behaviour into a "StartWalking" and "StopWalking" function - which you can just call (the float parameter to start walking is the same as the one you would put into MovePlayerForward).

Apologies if there any syntax errors, i am unable to test run the code from this computer.
(This post was last modified: 10-16-2012, 04:48 PM by Apjjm.)
10-16-2012, 04:44 PM
Find


Messages In This Thread
Forcing the player to walk - by Measuring - 01-08-2012, 10:02 AM
RE: Forcing the player to walk - by Dobbydoo - 01-08-2012, 10:13 AM
RE: Forcing the player to walk - by Statyk - 01-08-2012, 06:17 PM
RE: Forcing the player to walk - by Dobbydoo - 01-08-2012, 08:44 PM
RE: Forcing the player to walk - by Statyk - 01-08-2012, 10:19 PM
RE: Forcing the player to walk - by 4WalledKid - 10-16-2012, 04:02 PM
RE: Forcing the player to walk - by Apjjm - 10-16-2012, 04:44 PM



Users browsing this thread: 1 Guest(s)