- Home /
Rotating object phases through other objects
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;
}
}
Answer by Yoctometric · Jan 15, 2018 at 06:40 PM
Further info: It turns out the main issue was that my arm object did not have a rigidbody. I added one and set it to continuous, but now the arm does it's own thing and does not stick to the player.
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
Pysics not working as expected 1 Answer
Joystick move Left Right and down, plus rotation. 0 Answers
C# Water Rotation 0 Answers
2D C# Rotation Stopped Working Since Unity 5, Please Help? 0 Answers