I’m developing a 3D fighter game with my friends currently and currently we have a movement system where the player will constantly face the enemy. With the transform.TransformPosition() function they essentially orbit around the enemy, when the A key is pressed it will move to the left, however since the transform.TransformPosition() and constant rotation towards the enemy, it will move in a circle. This is exactly what we wanted. But the question is, how would we implement a dash key with the Q and E keys? I attempted to have a system work similar to the basic controls, having a Vector3 just for movement regarding the dash keys and translating it with TransformPosition(), but it didn’t work out very well.
Here’s my movement script
using UnityEngine;
using System.Collections;
public class CharController : MonoBehaviour {
//Created: August 21-28, 2015
//Creator: SwaggyMcChicken
//Purpose: Enables player to move, "orbitting" the enemy
//Edited: September 2, 2015
//Editor: SwaggyMcChicken
//Purpose: Implementing a "Dash" feature
public CharacterController CC;
//Reguarding Movement section
public float JumpHeight = 0f;
public float Speed = 6f;
public float Gravity = 5f;
public float DashSpeed = 10f;
bool Dashing = false;
Vector3 MoveDirection;
Vector3 DashDirection;
void Update () {
if(CC.isGrounded == true){
//Gets player input based on Axis (WASD)
MoveDirection = new Vector3 (Input.GetAxis ("Horizontal"), Input.GetAxis("Jump"), Input.GetAxis ("Vertical"));
//Translating from local cords
MoveDirection = transform.TransformDirection (MoveDirection);
//Multiplying to add Speed variable
MoveDirection *= Speed;
//If let dash key is pressed & player isn't currently dashing, change Vector3
if(Input.GetKey(KeyCode.E) && Dashing == false){
DashDirection.x = DashDirection.x + DashSpeed;
Dashing = true;
}
//Same as above, but to the right.
if(Input.GetKey(KeyCode.Q) && Dashing == false){
DashDirection.x = DashDirection.x - DashSpeed;
Dashing = true;
}
//Translating from local cords
DashDirection = transform.TransformDirection(DashDirection);
}
}
void FixedUpdate(){
if (CC.isGrounded == false) {
//Simulating Gravity and syncs with current deltaTime
MoveDirection.y -= Gravity * Time.deltaTime;
if (MoveDirection.y > 50) {
MoveDirection.y = 50;
Debug.Log (MoveDirection.y);
}
}
//Moves character
CC.Move(MoveDirection * Time.deltaTime);
//If player is dashing, use Vector3 to dash and set Dashing to false
if (Dashing == true) {
CC.Move (DashDirection * Time.deltaTime);
Dashing = false;
}
}
}
I could be overlooking this entirely. I do it often lol. Any help would be appreciated