I am making a Beat Saber game.
For the blue saber I used Quaternion.Slerp
to rotate it. There are 5 states for the saber:
0. do nothing
- cut from down to up
- cut from up to down
- cut from left to right
- cut from right to left
When I used Quaternion.Slerp
I only set it to change the x
position
but when I tested and cut with the saber it also changed the y
position
.
Here’s the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BlueSaberScript : MonoBehaviour
{
public bool selected = false;
public RedSaberScript red;
public float status = 0; // 0=nothing, 1=down-up, 2=up-down, 3=left-right, 4=right-left
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(1))
{
selected = true;
red.Unselect();
}
if(status == 0 && selected)
{
if(Input.GetKey(KeyCode.UpArrow))
{
status = 1;
}
else
{
if(Input.GetKey(KeyCode.DownArrow))
{
status = 2;
}
else
{
if(Input.GetKey(KeyCode.RightArrow))
{
status = 3;
}
else
{
if(Input.GetKey(KeyCode.LeftArrow))
{
status = 4;
}
}
}
}
}
//cut animations
if(selected)
{
if(status == 0)
{
Quaternion target = Quaternion.Euler(0f, transform.rotation.y, transform.rotation.z);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 10.0f);
}
else
{
if(status == 1)
{
}
else
{
if(status == 2)
{
Quaternion target = Quaternion.Euler(-150.695f, transform.rotation.y, transform.rotation.z);
transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * 5.0f);
status = 0;
}
else
{
if(status == 3)
{
}
else
{
if(status == 4)
{
}
}
}
}
}
}
}
public void Unselect()
{
selected = false;
}
}
Is there something wrong?