I have made a ragdoll for my game and now I want to make it's arms point towards the mouse.
The arms are connected to the torso with hinge joints.
Anything would help
here is my current code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotate : MonoBehaviour
{
private Vector3 mousePos;
public float addOn;
GameObject point;
void Start() {
point = transform.GetChild(0).gameObject;
}
void Update() {
mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
void FixedUpdate()
{
Vector3 difference = mousePos - point.transform.position;
difference.Normalize();
float rotationZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
print(rotationZ);
float currentRotation = transform.rotation.z;
transform.RotateAround(point.transform.position,new Vector3(0,0,1),rotationZ);
}
}
↧