- Home /
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 (:
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)
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.
@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.
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
Follow this Question
Related Questions
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