- Home /
Intentionally Delay FPS Controller Movement
Hey guys, I was wondering if anyone knew a way to intentionally delay, or cause some lag, on my FPS Controller movement. whether it be in the forms of a script or changing the settings on my FPS Controller. Long story short, I want the user to input a movement command but have it take a second before the controller responds and actually moves in game. I understand this is a bit taboo when making a game since a lot of effort is put into eliminating or minimizing lag, but for my project and the research I am trying to conduct, it is necessary.
Thanks!
Well, the simplest way would be to start a coroutine once inout is registered, and have that coroutine wait for a few frames or seconds and then do whatever the input should do (shoot, jump etc.).
Answer by M-Hanssen · May 11, 2016 at 10:24 AM
@Cherno is wright, try this:
public float Delay = 1;
protected void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(DelayExecution());
}
}
protected IEnumerator DelayExecution()
{
yield return new WaitForSeconds(Delay);
// Execute your delayed action
}
Okay so if I wanted to put the delay on the character movement you're saying I'd have to create a coroutine. In terms of and fps controller would I have to do it for each possible input? (i.e walk forward, backward, left, right, etc.)
I will attach my current script for my character controller, please give me a little more insight on how to go about implementing this coroutine. link text
Sorry but I'm not going to write your code for you...
You said you wanted to delay something and above is the solution. I still don't understand why you would want to reduce the fps for delaying some input, but just delaying the input would look something like this:
private IEnumerator GetInput(out float speed)
{
// Read input
float horizontal = CrossPlatformInput$$anonymous$$anager.GetAxis("Horizontal");
float vertical = CrossPlatformInput$$anonymous$$anager.GetAxis("Vertical");
bool waswalking = m_IsWalking;
yield return new WaitForSeconds(1);
#if !$$anonymous$$OBILE_INPUT
// On standalone builds, walk/run speed is modified by a key press.
// keep track of whether or not the character is walking or running
m_IsWalking = !Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift);
#endif
// set the desired speed to be walking or running
speed = m_IsWalking ? m_WalkSpeed : m_RunSpeed;
m_Input = new Vector2(horizontal, vertical);
// normalize input if it exceeds 1 in combined length:
if (m_Input.sqr$$anonymous$$agnitude > 1)
{
m_Input.Normalize();
}
// handle speed change to give an fov kick
// only if the player is going to a run, is running and the fovkick is to be used
if (m_IsWalking != waswalking && m_UseFov$$anonymous$$ick && m_CharacterController.velocity.sqr$$anonymous$$agnitude > 0)
{
StopAllCoroutines();
StartCoroutine(!m_IsWalking ? m_Fov$$anonymous$$ick.FOV$$anonymous$$ickUp() : m_Fov$$anonymous$$ick.FOV$$anonymous$$ickDown());
}
}
And start the coroutine in the fixedupdate like this:
StartCoroutine(GetInput(out speed));
Answer by CBRZY · May 12, 2016 at 01:51 PM
Are you trying to simulate inertia? Where the player resists going from one state to another, basically taking long before actually moving?
If so, I would recommend using 2 variables for speed.
Have a maxSpeed and a currentSpeed. maxSpeed being the main speed for moving or running. currentSpeed would start at 0 and when you start moving, getting input to move, you increase the currentSpeed from 0 until it gets to maxSpeed and use the currentSpeed as the movement modifier.
You can use a coroutine to increase the currentSpeed by 0.5 or something every few milliseconds. This will let the player start moving, but slowly and then the speed will increase to the maxSpeed. Basically simulating inertia.
Your answer
Follow this Question
Related Questions
Movement in Mid Air WITH a reduced speed 1 Answer
FPS Controller is inaccurate 2 Answers
2D player keeps getting dragged to the left for some reason. 0 Answers
Jittery FPS Camera when moving 3 Answers
How to crouch Smoothly 1 Answer