private Transform m_rightUpperArm;
float moveSpeed = 0.2f;
float turnSpeed = 20;
Vector3 lastMousePos = new Vector3(3, 3, 3);
Vector3 mousePosition;
Vector3 moveDirection;
private void Awake()
{
if (m_rightUpperArm == null)
m_rightUpperArm = transform.Find("ARM Right Arm");
if (m_rightUpperArm == null)
{
Debug.LogError("There is no 'm_rightUpperArm object as a child of the player");
};
}
private void Start()
{
moveDirection = Vector3.right
}
private void Update()
{
if (m_fireRate == 0)
{
if (Input.GetButton("Fire1"))
{
Debug.Log("Update().Fire1");
Rotate();
Shoot();
}
}
}
private void Rotate()
{
Vector3 currentPosition;
currentPosition = m_rightUpperArm.position;
mousePosition = Input.mousePosition;
mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
m_rightUpperArm.position = Vector2.Lerp(m_rightUpperArm.position, mousePosition, moveSpeed);
Vector3 moveToward;
moveToward = Camera.main.ScreenToWorldPoint(Input.mousePosition);
moveDirection = moveToward - currentPosition;
moveDirection.z = 0;
moveDirection.Normalize();
if (moveDirection != Vector3.zero)
{
float targetAngle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg - 90;
m_rightUpperArm.rotation = Quaternion.Slerp(m_rightUpperArm.rotation, Quaternion.Euler(0, 0, targetAngle), turnSpeed * Time.deltaTime);
}
}
I'm trying to rotate the right upper arm of my Player. m_rightUpperArm is a transform with the BoneFollower script attached. This doesn't work. What am doing wrong?