So I’m a beginner to unity, and making a quick little 2D game where the player’s arm holds a shovel can rotate with 180 degrees of freedom and is supposed to interact with snow (round sprites with circle colliders)
Both have colliders and rigidbodies, both are simulated, and they interact just fine if I rotate the arm very, very slowly. However, as soon as I move the arm quickly they pass right through each other.
I don’t quite understand the issue, but if anybody could help me even to just demonstrate how to rotate objects without this issue of phasing, I would greatly appreciate it.
using UnityEngine;
using System.Collections;
public class ArmRotator : MonoBehaviour {
void FixedUpdate ()
{
//WARNING! ARM CURRENTLY TELEPORTING THRU THE SNOW!
Vector2 mouse = Camera.main.ScreenToViewportPoint(Input.mousePosition); //Mouse position
Vector3 objpos = Camera.main.WorldToViewportPoint (transform.position); //Object position on screen
Vector2 relobjpos = new Vector2(objpos.x - 0.5f,objpos.y - 0.5f); //Set coordinates relative to object
Vector2 relmousepos = new Vector2 (mouse.x - 0.5f,mouse.y - 0.5f) - relobjpos;
float angle = ((Vector2.Angle (Vector2.up, relmousepos)) -90f) / 1.5f; //Angle calculation
//if (relmousepos.x > 0)
// angle = 360-angle;
Quaternion quat = Quaternion.identity;
quat.eulerAngles = new Vector3(0,0,angle); //Changing angle
transform.rotation = quat;
}
}