Mount and Blade Combat System Attacking The Same Direction When Going A Different Direction
Hi, I have just started on this directional attack system. When the player's rotation is negative when right clicked it should swing from the right vise verse(for up and down as well). Whenever I attack from the right, left, above or below it will do the same output multiple times. Sometimes it changed output, but not when it should. I noticed in unity that only the x rotation axis is moving, none of the other move at all. When I click play and rotate them manually they don't move at all. So at the moment x is for up, down, left and right which is strange. I have looked at other articles but they seem to be doing it a different way by splitting the screen up in to different segments for the attack so they have not been too much help. Any help would be greatly appreciated. Thank you.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class camMouseLook : MonoBehaviour {
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 5.0f;
public float smoothing = 2.0f;
public Quaternion lastInputLeftRightQ;
public float lastYInputLeftRightDirection;
public Quaternion lastInputUpDownQ;
public float lastYInputUpDownDirection;
public GameObject player;
public bool hasSwung = false;
public float cooldownTimer = 1;
public bool isDead = false;
GameObject character;
void Start()
{
character = this.transform.parent.gameObject;
}
void LateUpdate()
{
if (isDead == false)
{
var md = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));
md = Vector2.Scale(md, new Vector2(sensitivity * smoothing, sensitivity * smoothing));
smoothV.x = Mathf.Lerp(smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp(smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
mouseLook.y = Mathf.Clamp(mouseLook.y, -90f, 90f);
transform.localRotation = Quaternion.AngleAxis(-mouseLook.y, Vector3.right);
character.transform.localRotation = Quaternion.AngleAxis(mouseLook.x, character.transform.up);
}
}
void Update()
{
if (hasSwung == false)
{
lastYInputLeftRightDirection = 0;
lastYInputUpDownDirection = 0;
lastInputLeftRightQ = character.transform.rotation;
lastYInputLeftRightDirection = lastInputLeftRightQ.y;
lastInputUpDownQ = character.transform.rotation;
lastYInputUpDownDirection = lastInputUpDownQ.x;
}
if (Input.GetButtonDown("Fire2") && hasSwung == false)
{
if (player.transform.rotation.x == lastYInputLeftRightDirection)
{
Debug.Log("didn't swing left or right");
}
if (player.transform.rotation.x == lastYInputLeftRightDirection)
{
Debug.Log("didn't swing up or down");
}
if (player.transform.rotation.x > lastYInputLeftRightDirection)
{
Debug.Log("left");
hasSwung = true;
StartCoroutine(Cooldown());
}
if (player.transform.rotation.x < lastYInputLeftRightDirection)
{
Debug.Log("right");
hasSwung = true;
StartCoroutine(Cooldown());
}
if (player.transform.rotation.y > lastYInputUpDownDirection)
{
Debug.Log("up");
hasSwung = true;
StartCoroutine(Cooldown());
}
if (player.transform.rotation.y < lastYInputUpDownDirection)
{
Debug.Log("down");
hasSwung = true;
StartCoroutine(Cooldown());
}
}
}
public IEnumerator Cooldown(float countdownValue = 10)
{
while (cooldownTimer > 0)
{
yield return new WaitForSeconds(1.0f);
cooldownTimer--;
}
if (cooldownTimer <= 0)
{
hasSwung = false;
}
}
}
Your answer
Follow this Question
Related Questions
Make enemy face left or right depending on player position 1 Answer
Problem with raycasting towards mouse 0 Answers
Problem with destroying a gameobject 2 Answers
making object move forward 0 Answers