Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Symbie · Jul 28, 2020 at 03:27 AM · charactercontrollerfirst person controllerdash

3D Dash ability

I am trying to make a dash ability for a 3D first person game i am making, but i am stuck. i made a script for the camera control and a script for the movement, in that is the dash i am trying to make. i want the dash to bring the player forward some in whatever direction theyre facing, and such. but at the moment the dash shoots the player up and im not sure why. these are the scripts

Camera Control:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerLook : MonoBehaviour
 {
     [SerializeField]
     private string mouseXInputName, mouseYInputName;
 
     [SerializeField]
     private float mouseSensitivity;
 
     [SerializeField]
     private Transform playerBody;
 
     private float xAxisClamp;
 
     void Awake()
     {
         LockCursor();
         xAxisClamp = 0.0f;
     }
 
     private void LockCursor()
     {
         Cursor.lockState = CursorLockMode.Locked;
     }
 
     private void Update()
     {
         CameraRotation();
     }
 
     private void CameraRotation()
     {
         float mouseX = Input.GetAxis(mouseXInputName) * mouseSensitivity * Time.deltaTime;
         float mouseY = Input.GetAxis(mouseYInputName) * mouseSensitivity * Time.deltaTime;
 
         xAxisClamp += mouseY;
 
         if(xAxisClamp > 90.0f)
         {
             xAxisClamp = 90.0f;
             mouseY = 0.0f;
             ClampXAxisRotationToValue(270.0f);
         }
         else if (xAxisClamp < -90.0f)
         {
             xAxisClamp = -90.0f;
             mouseY = 0.0f;
             ClampXAxisRotationToValue(-270.0f);
         }
 
         transform.Rotate(Vector3.left * mouseY);
         playerBody.Rotate(Vector3.up * mouseX);
 
     }
 
     private void ClampXAxisRotationToValue(float value)
     {
         Vector3 eulerRotation = transform.eulerAngles;
         eulerRotation.x = value;
         transform.eulerAngles = eulerRotation;
     }
 }

Player Movement (with the broken dash)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerMove : MonoBehaviour
 {
     [SerializeField]
     private string horizontalInputName;
 
     [SerializeField]
     private string verticalInputName;
 
     [SerializeField]
     private float movementSpeed;
 
     private CharacterController charController;
 
     private float dashSpeed = 100f;
 
     private void Awake()
     {
         charController = GetComponent<CharacterController>();
     }
 
     private void Update()
     {
         PlayerMovement();
     }
 
     private void PlayerMovement()
     {
         float horizInput = Input.GetAxis(horizontalInputName) * movementSpeed;
         float vertInput = Input.GetAxis(verticalInputName) * movementSpeed;
 
         Vector3 forwardMovement = transform.forward * vertInput;
         Vector3 rightMovement = transform.right * horizInput;
 
         charController.SimpleMove(forwardMovement + rightMovement);
 
         if (Input.GetKeyDown(KeyCode.T))
         {
             charController.Move(transform.position * dashSpeed * Time.deltaTime);
         }
     }
 }

any suggestions on how to make a better dash script would be much appreciated, i know the mess i have now isnt very good, Thanks (:

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 Llama_w_2Ls · Jul 28, 2020 at 11:23 AM

         if (Input.GetKeyDown(KeyCode.Q))
         {
             Walkspeed = 20;
             controller.Move(move * Walkspeed * Time.deltaTime);
 
             Start:
 
             Walkspeed -= SpeedIncrease;
             Debug.Log(Walkspeed);
 
             if (Walkspeed > 6)
             {
                 goto Start;
             }
         }

Well this is how i did it (inside of update method)

Comment
Add comment · Show 3 · 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 Symbie · Jul 29, 2020 at 12:35 AM 0
Share

I see how you did controller.$$anonymous$$ove(move Walkspeed Time.deltaTime); But with the way i coded $$anonymous$$e, i dont have a (i assume yours is a Vector3 for moving) Vector3 as i used simplemove for my movement, so i dont think i can apply this to my code, unless im wrong and stupid, im not sure.

avatar image smillyfaces Symbie · Jul 29, 2020 at 03:05 AM 0
Share

@Symbie i think i have a fix, simply replace $$anonymous$$ove with simple$$anonymous$$ove as shown here: if (Input.GetKeyDown(KeyCode.Q)) { float currentdash = dashspeed; charController.Simple$$anonymous$$ove(forward$$anonymous$$ovement * currentdash + right$$anonymous$$ovement);; Start: currentdash -= SpeedIncrease; Debug.Log(Walkspeed); if (currentdash > 6) { goto Start; } } though I'm no entirely sure if this will work as i haven't worked with simple$$anonymous$$ove before, but its always worth a try.

avatar image Symbie smillyfaces · Jul 29, 2020 at 04:30 AM 0
Share

Thank you for the help, but after looking at what both of you said i found my own, simpler solution. what i did was change

          if (Input.GetKeyDown(KeyCode.T))
          {
              charController.$$anonymous$$ove(transform.position * dashSpeed * Time.deltaTime);
          }

To

          if (Input.GetKeyDown(KeyCode.T))
          {
              charController.$$anonymous$$ove(forward$$anonymous$$ovement * dashSpeed * Time.deltaTime);
          }

this seems to work. you press T and the character jumps forward, this only works if you are already going forward. at first i wanted to change this so that it would work no matter what, but i like it being that it only works if moving forward. now the issue is that it is so instant. is there a way to make it look better, instead of the player just teleporting to the spot?

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

154 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

Related Questions

Character Controller based 'dash' function moves strangely in one direction, despite values seemingly being correct. 0 Answers

Is this a good way to implement a dash for my first person controller? 0 Answers

First person dash advice 0 Answers

Dash where your looking 1 Answer

Smoother dash with a Character Controller 2 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