- Home /
Character pass trought wall...
Hello, i have a little problem, i know thats its not a big problem but i dont know how to repair it. my character pass trought wall with one script but not with the other.. with this script (The Good) i pass trought my wall :
var speed = 13;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
if (Input.GetKey("w") || Input.GetKey("s"))
{
transform.Translate(0, 0, Input.GetAxisRaw("Vertical") * Time.deltaTime * speed); //Axe Z
}
if (Input.GetKey("a") || Input.GetKey("d"))
{
transform.Translate(Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed, 0, 0); //Axe X
}
}
//Mettre la gravité
moveDirection.y -= gravity * Time.deltaTime;
// Bouger le joueur
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
and with my older script he did not pass :
var speed = 13;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
if (grounded) {
moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
//Mettre la gravité
moveDirection.y -= gravity * Time.deltaTime;
// Bouger le joueur
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags & CollisionFlags.CollidedBelow) != 0;
}
@script RequireComponent(CharacterController)
My wall have a mesh collider on it because it is a model 3D .. This one : http://www.fileserve.com/file/WthEprQ/level 1.FBX
Answer by MountDoomTeam · Dec 03, 2012 at 09:24 AM
With one of the scripts, you are translating the player, so you are in effect pushing him,
With the other script, your changing his transform.position,
Transform.position override the physics it's as simple as that.
the scripts use different movement commands, one is relative to player the other is relative to world position. if you want to override the wall, you can turn off the wall collider if character wall distance smaller than 1.
Use teh second script, the one that works. There is no use for a Character Controller is yuo do not use teh functions that go with it.
http://answers.unity3d.com/questions/26844/enabledisable-specific-components.html for turn on off rigidbody, look for enable component unity on google
You should avoid having rigidbody and character controller on the same guy. You will see some weird behaviors as each kinda tries to overlap the features of the other.
ya if you need to turn off a rigidbody, do that on the wall, otherwise player can fall through the floor.
Your answer