Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ODoyleRules · May 11, 2016 at 10:04 AM · unity 5movementdelayfps controller

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!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · May 11, 2016 at 10:08 AM 0
Share

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.).

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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
     }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ODoyleRules · May 12, 2016 at 07:30 AM 0
Share

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

firstpersoncontroller.txt (9.7 kB)
avatar image M-Hanssen ODoyleRules · May 12, 2016 at 08:26 AM 0
Share

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));
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges