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
Measuring Offline
Member

Posts: 130
Threads: 16
Joined: Dec 2011
Reputation: 15
#1
Forcing the player to walk

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!

The Facility
Tenebris Lake
Killings In Altstadt
01-08-2012, 10:02 AM
Find
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#2
RE: Forcing the player to walk

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

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

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

01-08-2012, 10:13 AM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#3
RE: Forcing the player to walk

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
}
(This post was last modified: 01-08-2012, 06:23 PM by Statyk.)
01-08-2012, 06:17 PM
Find
Dobbydoo Offline
Member

Posts: 50
Threads: 6
Joined: Aug 2011
Reputation: 0
#4
RE: Forcing the player to walk

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
01-08-2012, 08:44 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#5
RE: Forcing the player to walk

(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 =\
01-08-2012, 10:19 PM
Find
4WalledKid Offline
Member

Posts: 107
Threads: 23
Joined: Oct 2012
Reputation: 1
#6
RE: Forcing the player to walk

(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?

[Image: 4walledkidbanner_zps1514b7f6.png]
10-16-2012, 04:02 PM
Website Find
FlawlessHappiness Offline
Posting Freak

Posts: 3,980
Threads: 145
Joined: Mar 2012
Reputation: 171
#7
RE: Forcing the player to walk

How about removing the timer? Tongue

Trying is the first step to success.
10-16-2012, 04:03 PM
Find
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




Users browsing this thread: 1 Guest(s)