Hello! I want to make something similar to Archvale’s weapon rotation. i have made the weapon rotating the player only i need is when i left click the sword will flip.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sword : MonoBehaviour
{
// Point you want to have sword rotate around
public Transform shoulder;
// how far you want the sword to be from point
public float armLength = 1f;
bool facingright = false;
// Start is called before the first frame update
public KeyCode attack1;
void Start()
{
// shoulder = transform.parent.transform;
}
// Update is called once per frame
void Update()
{
// Get the direction between the shoulder and mouse (aka the target position)
Vector3 shoulderToMouseDir = Camera.main.ScreenToWorldPoint(Input.mousePosition) - shoulder.position;
shoulderToMouseDir.z = 0; // zero z axis since we are using 2d
// we normalize the new direction so you can make it the arm's length
// then we add it to the shoulder's position
Vector3 mousePosition = Input.mousePosition;
// mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
// Vector2 direction = new Vector2(mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);
// transform.right = direction;
//Flip
// Vector3 SwordScale = transform.localScale;
// if (mousePosition.x < transform.position.x)
// {
// SwordScale.y = -1;
// SwordScale.x = -1;
// }
// else if (mousePosition.x > transform.position.x)
// {
// SwordScale.y = 1;
// SwordScale.x = 1;
// }
// transform.localScale = SwordScale;
transform.position = shoulder.position - (armLength * shoulderToMouseDir.normalized);
if (Input.GetKeyDown(attack1) && !facingright){
// SwordScale.y = -1;
facingright = true;
}
else if(Input.GetKeyDown(attack1) && facingright){
// SwordScale.y = 1;
facingright = false;
}
}
}