- Home /
Character Controller - Collision Detection
Hello,
Haven't used Unity for a while, but I struggling to get a ball to move when my character walks into it?! I honestly thought it would be pretty simple?
So, I'm using the 3rd person controller, and I also have a sphere with a rigidbody in the scene. All I want to do, is to walk into the ball, and have that ball move as I move into it. All that happens is my character stops walking as if the ball is a solid wall?! Although, when I select my character in the Editor, and force him into the ball, it then moves...
What am I doing wrong here?
Thanks
Answer by maroonrs2 · May 06, 2012 at 09:03 PM
DO NOT USE 3RD PERSON CONTROLLER!1!1!1 Just take that out and place a new capsule. Add rigidbodies to each of the objects. Move the camera into it like first person to test it. Then make your adjustments to make the cam third person. Then use this:
var MoveForce:float = 10;
var xSensitivity : float;
var ySensitivity : float;
var maxHeight : float;
var minHeight : float;
private var xPos : float;
private var yPos : float;
var myTrans : Transform;
var camTrans : Transform;
function Update () {
yPos = Mathf.Clamp(yPos - Input.GetAxis ("Mouse Y") * ySensitivity, minHeight, maxHeight);
xPos = xPos + Input.GetAxis("Mouse X") * xSensitivity;
myTrans.rotation = Quaternion.AngleAxis(xPos, Vector3.up);
camTrans.localRotation = Quaternion.AngleAxis(yPos, Vector3.right);
rigidbody.SetMaxAngularVelocity(10);
var inputVector : Vector3 = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
rigidbody.AddForce(tranform.TransformDirection(inputVector * MoveForce), ForceMode.Force);
}