- Home /
How to stop CharacterController during Collider's moving?
Hi all.
I have two cubes, one attached FPSInputController.js and CharacterMotor.js, regarded as controller. The other acts as a collider.
What I want to achieve is that after two cubes' collision, the collider moves away in several frames/seconds in a certtain distance, and the controller stops moving during the collider's moving (maybe cant receive the keyboard's message or doing nothing after receive these messages).
Now the collider moves as my expection. But I dont know how to stop the controller immediately. I try to change CharacterController.velocity to zero while this variant is read-only. I also try to retrive the controll's transform.position every frame but it always changes uncontrolable.
My script is as follow. I attach this script to the controller to catch collision.
#pragma strict
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.collider.name != "Terrain")
{
Precomp.controller = hit.controller;
Precomp.cube = hit.collider;
Precomp.flag = true;
Precomp.dir = hit.moveDirection;
}
}
And the Precomp.js is as follow. I attach this script to the Main Camera to deal with the collision.
#pragma strict
static var controller : CharacterController;
static var cube : Collider;
static var flag : boolean;
static var dir : Vector3;
var count:byte = 0;
function Update () {
if(flag == true)
{
if(count<5) {
cube.transform.position += (dir/5);
count++;
}
else
{
count = 0;
flag = false;
}
}
}
Now how to stop the controller during collider's moving?
Your answer
Follow this Question
Related Questions
Character Controller OnControllerColliderHit never called. 0 Answers
Getting Character controller to fit model? 0 Answers
Ignore collision at high velocity. 1 Answer
OnCollisionEnter does not work 4 Answers