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 /
  • Help Room /
avatar image
0
Question by SageGlaze · Feb 24, 2019 at 10:01 AM · scripting problemfpscontroller

FPS Controller

So I'm working on scripting a dashing/blinking ability for an FPS game. I want this ability to be limited to the X axis, I don't want the player to be able to dash/blink forward. I have intended for this ability to require the player to hold the left shift key and press 'A' or 'D'. I've tried a few methods as best as I could understand them like mathf.lerp, vector3.lerp, transform.position += blah * blah blah.


Eventually I reached a point where I seemed to be getting a reaction from the engine as when I tried to make my character blink/dash to the right (left shift + D) my screen flickered but my character had not moved aside ofcourse having taken one step in my attempt. I noticed the flicker seemed most prominent to the left side of my scene, which is a very basic platform with a single wall and a point light.


I tried producing the dash/blink a few more times but with my character facing the left side of my scene. I then noticed that the flicker was a duplicate of my scene appearing down the negative end of the X axis and quickly disappearing.


Not sure if this DOES mean I was getting close but I sure like to take it as a sign of such. Unfortunately I don't have a script to attach as I've completely scrapped the one I had in progress thankfully my question, atleast for now, is not so much about the exact implementation of such a mechanic but rather if trying to create this mechanic in a script separate from the unity FPS controller script could be conflicting with this? Or better yet if using the FPS character prefab at all is conflicting with the implementation of custom behaviors? Would I have to create my own 'character' with a character controller component and script?

Comment
Add comment
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

1 Reply

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

Answer by SageGlaze · Feb 25, 2019 at 12:51 PM

Alright I seem to have figured it out and now have a working blink mechanic. I guess the issue was the fact that the FPS character in the standard assets pack has a character controller component and that was indeed conflicting with the methods I was trying to use to apply the movement to the character. I had to access the character controller component and use controller.Move


I would like to point out one thing I noticed with testing it. Every time I started the game the first time I blinked seemed to travel farther than any blinks that followed, not a huge issue, but definitely noticeable. On a good note though the player doesn't seem to be able to blink through walls! Here's the script I really hope this helps someone. Happy Coding!


 public class Blink : MonoBehaviour
     {
         public float blinkForce = 200f;
         public float blinkStoppingSpeed = 0.1f;
         public float maxBlinkTime = 1f;
         public bool hasBlinked;
 
         private CharacterController controller;
         private Vector3 blinkDirection;
         private float currentBlinkTime;
 
         void Start()
         {
             controller = GetComponent<CharacterController>();
             hasBlinked = false;
         }
 
         void Update()
         {
             if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.D) && hasBlinked == false)
             {
                 hasBlinked = true;
                 BlinkRight();
                 Debug.Log("Blinked Right");
                 StartCoroutine(BlinkCoolDown());
             }
 
             if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.A) && hasBlinked == false)
             {
                 hasBlinked = true;
                 BlinkLeft();
                 Debug.Log("Blinked Left");
                 StartCoroutine(BlinkCoolDown());
             }
 
             if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.W) && hasBlinked == false)
             {
                 hasBlinked = true;
                 BlinkAhead();
                 Debug.Log("Blinked Ahead");
                 StartCoroutine(BlinkCoolDown());
             }
         }
 
         void BlinkRight()
         {
             currentBlinkTime = 0.0f;
             if (currentBlinkTime < maxBlinkTime)
             {
                 blinkDirection = controller.transform.right;
                 currentBlinkTime += blinkStoppingSpeed;
             }
             else
             {
                 blinkDirection = Vector3.zero;
             }
 
             controller.Move(blinkDirection * Time.deltaTime * blinkForce);
         }
 
         void BlinkLeft()
         {
             currentBlinkTime = 0.0f;
             if (currentBlinkTime < maxBlinkTime)
             {
                 blinkDirection = controller.transform.right * -1;
                 currentBlinkTime += blinkStoppingSpeed;
             }
             else
             {
                 blinkDirection = Vector3.zero;
             }
 
             controller.Move(blinkDirection * Time.deltaTime * blinkForce);
         }
 
         void BlinkAhead()
         {
             currentBlinkTime = 0.0f;
             if (currentBlinkTime < maxBlinkTime)
             {
                 blinkDirection = controller.transform.forward;
                 currentBlinkTime += blinkStoppingSpeed;
             }
             else
             {
                 blinkDirection = Vector3.zero;
             }
 
             controller.Move(blinkDirection * Time.deltaTime * blinkForce);
         }
 
         public IEnumerator BlinkCoolDown()
         {
             yield return new WaitForSeconds(2f);
             hasBlinked = false;
         }
     }


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

275 People are following this question.

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

Related Questions

Animations Bad Scripting | Controller Script Buggy | Collider Problem | Beginner Here! 0 Answers

BasicFPS controller "Can not be loaded" 0 Answers

I am trying to make character jump in my FPS game. However, he only jumps small height and gets back down to the ground almost immediately. Can anyone help me with the script? 1 Answer

Script creating 2 prefabs instead of 1 0 Answers

What changed in 2018.3 that prevents teleporting the FPSController in Standard Assets 0 Answers


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