How i stop Player rotation when collide
I have a player who move around a pillar, for this I use transform.Translate() in axes Y to move Up/Down, and transform.RotateAround(), to rotate around the pillar.
I put some obstacles in the pillar, but when the player collide with one of this pillars (using the rotate around), he "climb" the pillar. I try use freeze rotate for prevent the player of rotate around your own axes, but doesn't work.
My Script for move is like this:
public class Movement : MonoBehaviour {
public VirtualJoystick joystick;
private GameObject player;
private Rigidbody rgb;
void Start(){
rgb = GetComponent<Rigidbody> ();
rgb.constraints = RigidbodyConstraints.FreezeRotation;
}
void FixedUpdate () {
if(joystick.inputVector.x > 0){
transform.RotateAround (Vector3.zero, Vector3.up, joystick.inputVector.x * (-50) * Time.deltaTime);
Debug.Log ("X: "+joystick.inputVector.x);
Debug.Log ("Time: "+Time.deltaTime);
}
if( joystick.inputVector.x < 0){
transform.RotateAround (Vector3.zero, Vector3.down,joystick.inputVector.x * 50 * Time.deltaTime);
Debug.Log ("X: " + joystick.inputVector.x);
}
if(joystick.inputVector.z > 0){
transform.Translate (0, (3 * Time.deltaTime),0);
Debug.Log ("UP: "+joystick.inputVector.z);
}
if(joystick.inputVector.z < 0){
transform.Translate (0, (-3 * Time.deltaTime),0);
Debug.Log ("UP: "+joystick.inputVector.z);
}
}
private void OnCollisionEnter(Collision collider){
rgb.rotation = Quaternion.identity;
}
}
I try stop the player rotate when collide using quaternion but doesn't work too.
How can i prevent the player to "walk" in the superficie of the obstacle when he collide with it?
Answer by Flokky_ · Sep 19, 2017 at 07:08 AM
If I've understand clearly, then you just have to try set constraints on your rigidbody. Freeze rotation axis x, y, z.
Answer by lkledu · Sep 19, 2017 at 12:35 PM
i try this, but didn't work. I think it's because i was using rotateAround for move my player.