I am having some serious problems with the way my character controls. I have a custom code that isn’t complex at all, so it’s not the character controller preset. Anyways, whenever the player hits a wall, it kinda vibrates against it, trying again and again to go through it. I’d rather the player run into the wall, and just be forced to stop moving.
I tried writing something in the OnCollisionEnter function about when the player hits the wall to reduce the speed to 0, but then the player cant move. I even set it up so that if the character hits it and the speed is dropped to zero, that when the player turns around, it can accelerate in the turned-around direction.
Does anybody have some techniques to make a character whose collision isn’t done through ray casting, but rather all just collision boxes, STOP colliding strangely with walls? I’ll link you to a video to show what is happening.
Also, here is my code:
private var done = false;
var spawnPoint : Transform;
var speed : int = 5;
var jumpSpeed: float = 8;
var isgrounded : boolean = true;
var isRight : boolean = true;
var LevelComplete : boolean;
var canMove: boolean = true;
function Start () {
}
function Update () {
Movement();
textureChanges();
}
function Movement (){
if(!LevelComplete){
Camera.main.transform.position = new Vector3(transform.position.x, 1, transform.position.z + 30);
if(canMove){
// if(Input.GetAxis("Horizontal")){
// transform.Translate(Vector3(Input.GetAxis("Horizontal") * speed * Time.deltaTime, 0, 0));
// }
var colliderBox = gameObject.GetComponent(BoxCollider); //controlls collider box size
var AT = gameObject.GetComponent(AnimateTexture); //Store AnimateTexture Script
if(Input.GetKey("a")){ //Player moves left
AT.rowNumber = 1;
transform.Translate(Vector2.right * speed * Time.deltaTime);
isRight = false;
} else if(Input.GetKey("d")){
AT.rowNumber = 1;
transform.Translate(-Vector2.right * speed * Time.deltaTime);
isRight = true;
} else { //Player is not moving
AT.rowNumber = 0; //Change to idle animation!
}
if(isgrounded == true){
if(Input.GetKeyDown("space")){
AT.rowNumber = 3; //Player jumping animation
rigidbody.velocity += Vector3.up * jumpSpeed;
Physics.gravity = Vector3(0, -85, 0);
}
}
if(isgrounded == false){
colliderBox.center = Vector3(0.03, -0.08, 0);
colliderBox.size = Vector3(.5, .7, .5);
}
else if(Input.GetKey("s")){
AT.rowNumber = 4; //Player squats down
colliderBox.center = Vector3(0.03, -0.39, 0);
colliderBox.size = Vector3(0.44, 0.18, 1);
}
else {
colliderBox.center = Vector3(0.03, -0.2965, 0);
colliderBox.size = Vector3(0.44, 0.37, 1);
}
}
}
}
Any suggestions?? This jagged hitting crap is so annoying, and I have no idea why the character is registering as on the ground when it’s clearly not (allowing more jumps to happen). sigh.
I AM NOT USING A CHARACTER CONTROLLER!!!
Also, yes, I have tried changing the physics material on the walls. Nothing works…