Frictional Games Forum (read-only)
[SCRIPT] Forcing the player to walk - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Forcing the player to walk (/thread-12456.html)



Forcing the player to walk - Measuring - 01-08-2012

I'm trying to script a cutscene and i want the player to move in a direction. Can i get some help scipting this?

I tried using MovePlayerForward(float afAmount) but it gives me and error and on the wiki page it says i need to use it with a timer that updates 60 times per second. How do i do that?

Thank you for your time!



RE: Forcing the player to walk - Dobbydoo - 01-08-2012

You need Justine to use MovePlayerForward.
To update a timer I think you have to do it like this:

PHP Code:
void Onstart()
{
  
AddTimer(""1"TimerName");
}

void TimerName(string &in asTimer)
{
  
MovePlayerForward(1);
  
 
//Now the timer will repeat itself once per second
  
AddTimer(""1"TimerName")




RE: Forcing the player to walk - Statyk - 01-08-2012

Going with the previous script, make the timers have 0.01f instead of 1... It needs to update 60 times a second. Setting it to 1 will have it update only once a second, which is not enough. Also, it needs another time to call back on the previous timer. So you should have 3 "AddTimer"s instead of only two. Like this:

void Onstart()
{
AddTimer("", 0, "TimerName");
}

void TimerName(string &in asTimer)
{
MovePlayerForward(1);
AddTimer("", 0.01f, "TimerName2"); //timer calls the timer that re-runs it instantly.
}


void TimerName2(string &in asTimer)
{
AddTimer("", 0, "TimerName"); //timer reverts back to the previous function and loops
}


RE: Forcing the player to walk - Dobbydoo - 01-08-2012

I misread, I thought it said once 60 times per minute, sorry about that. But is there a difference when you have three timers instead of only two? The ones I have in the custom story I'm working on works perfectly with only two. At least I think they do :S



RE: Forcing the player to walk - Statyk - 01-08-2012

(01-08-2012, 08:44 PM)Dobbydoo Wrote: I misread, I thought it said once 60 times per minute, sorry about that. But is there a difference when you have three timers instead of only two? The ones I have in the custom story I'm working on works perfectly with only two. At least I think they do :S
The function "TimerName" can't have a function that calls it again. It has to call another function that goes back. I don't know why, but it only seems to work this way for me =\


RE: Forcing the player to walk - 4WalledKid - 10-16-2012

(01-08-2012, 10:19 PM)Statyk Wrote:
(01-08-2012, 08:44 PM)Dobbydoo Wrote: I misread, I thought it said once 60 times per minute, sorry about that. But is there a difference when you have three timers instead of only two? The ones I have in the custom story I'm working on works perfectly with only two. At least I think they do :S
The function "TimerName" can't have a function that calls it again. It has to call another function that goes back. I don't know why, but it only seems to work this way for me =\

Is there any way to stop the MovePlayerForward?


RE: Forcing the player to walk - FlawlessHappiness - 10-16-2012

How about removing the timer? Tongue


RE: Forcing the player to walk - Apjjm - 10-16-2012

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.
Code:
//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.