I want to make a weapon for my game kind of like the scythe in Neon Sundown, but I don’t know how I would do this. It needs to spin around it’s pivot point at a constant rate, and orbit the player at a constant rate. If you need extra information, leave a comment and i will clarify as needed.
Isn’t the scythe just rotating around an offset origin?
You do this with a matrix transformation but the easiest way would just to be to parent it to another object, offset it from the origin and then rotate it.
Failing that you could set the x pos to the sin(theta) and the y or z pos to the cos(theta) (multiplied by the radius you want).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpinningWeapon : MonoBehaviour
{
public bool parent;//so that I can reuse the script and toggle this to true for the parent of the weapons (an empty object)
float v;
void FixedUpdate()
{
float fireRate = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>().fireRate;
if (parent == true)
{
transform.rotation = transform.parent.rotation * Quaternion.Inverse(Quaternion.Euler(0f, 0f, (fireRate * 7) * v));//rotates the weapon's parent around it's pivot while keeping from rotating with it's parent object (the player)
}
else
{
transform.Rotate(0f, 0f, -fireRate * 10);//rotates the weapon around it's pivot
}
v += 0.5f;//modifies the rotation set by transform.rotation so that it actually rotates instead of remaining stationary
if (v > 500000000f)//so that v doesn't go over the integer limit
{
v = 0f;
}
}
}
I solved it! Now I have functional spinning weapons!