- Home /
Why doesn't my playerobject collide with other objects?
Hello, I have a script that makes my character move automatically and hadles all the movement, but now it doesn't collide with objects EXCEPT for their top side (so you can move on top of any object but casually go through it). Can you tell me how do I fix it?
When I use the standard FPSInput script, it collides normally.
#pragma strict
public var theCamera : Transform;
private var movementSpeed : float = 5;
private var myTransform : Transform;
function Start()
{
myTransform = this.transform;
Screen.showCursor = false;
}
function Update()
{
// get inputs
var inputX : float = Input.GetAxis( "Horizontal" );
var inputY : float = Input.GetAxis( "Vertical" );
var directionVector = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
transform.Translate(Vector3.forward * 6 * Time.deltaTime, Space.Self);
// get current position, then do calculations
var moveVectorX : Vector3 = theCamera.forward * inputY;
var moveVectorY : Vector3 = theCamera.right * inputX;
var moveVector : Vector3 = ( moveVectorX + moveVectorY ).normalized * movementSpeed * Time.fixedDeltaTime;
// update Character position
myTransform.position = myTransform.position + Vector3( moveVector.x, 0.0, moveVector.z );
// and rotation
myTransform.LookAt( myTransform.position + Vector3( moveVector.x, 0.0, moveVector.z ) );
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
if (Input.GetKeyDown ("space")){
transform.Translate(Vector3.up * 230 * Time.fixedDeltaTime, Space.World);
audio.Play();
}
if (Input.GetKeyDown ("r")){
Application.LoadLevel(Application.loadedLevel);
}
}
Comment
Your answer