Question by
samhalsall · Jan 27, 2017 at 12:49 AM ·
rotationcollisionstop animations
How to stop object rotation when FPSController collides with object?
I have a rotating cube, and I want the cube to stop motion when the FPS controller comes into a certain distance within the cube, or collides with the cubes box collidor, but I cant figure out how to do it! This is what I have so far, but there is an error message with the RigidBody.. Any ideas?
using UnityEngine; using System.Collections;
public class Spin : MonoBehaviour {
public float speed = 10f;
void Update()
{
transform.Rotate(Vector3.up, speed * Time.deltaTime);
}
void OnCollisionEnter(Collision collision)
{
int knockback = 5 ;
if(collision.gameObject.tag == "ship")
{ if(Physics.Raycast(transform.position,Vector3.right,10))
{
Rigidbody.velocity = -transform.right * knockback;
}
if(Physics.Raycast(transform.position,Vector3.left,10))
{
Rigidbody.velocity = transform.right * knockback;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Rotate camera on collision of character 1 Answer
I have two RaycastHit2Ds but only one is activating 0 Answers
How do I unlock Z axis rotation after collision with an obstacle? 0 Answers
how can I align a rotating block that falls onto another with the correct face? 2 Answers
How to move and rotate to other direction when hitting a wall 1 Answer