Does any one know how to make sword swing animation like archvale game ?

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;
        }
    }
}
1 Like

I mean if all you want to flip the sword sprite changing their scale to the negative should be all you need to do, looking at the code is it not what the commented out code does?

it’s just flip it doesn’t feel right. it doesn’t change sa position like in the video. but if i change the position it won’t move

If you could change at what point it flips, might help? Then you can change its pivot point so it rotate at where you want.

Else there is using animation to move it around and parent it to the character so it always near the character, should be able to move it however you want?