- Home /
Terrain Collision Glitch
I created a terrain and i added my player prefab.
That done this : My player collide with a slope, and the collision glitch. Why? Here's my movement code:
#pragma strict
@Header("Statistics")
@Range(0,5)
var speed : float;
@Range(0,50)
var jumpForce : float;
var playerRigidbody : Rigidbody;
var inputAxis : Vector3;
var grounded : boolean;
@Header("OverlapSphere")
var groundSphereRadius : float;
var groundLayers : LayerMask;
var debugCollision : boolean;
var check : Vector3;
@Header("Debug")
var realSpeed : float;
var speedMultiplicator : float;
var smoothTime : float;
function FixedUpdate () {
var horizontalDivisor : float;
inputAxis = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
var realInputAxis : Vector3;
if(Input.GetButton("Run") && grounded){
speedMultiplicator = 2;
horizontalDivisor = 2;
}else if(Input.GetButton("Crouch") && grounded){
speedMultiplicator = 0.5;
horizontalDivisor = 1;
}else{
speedMultiplicator = 1;
horizontalDivisor = 1;
}
realInputAxis = Vector3(Input.GetAxis("Horizontal") / horizontalDivisor, 0, Input.GetAxis("Vertical"));
realSpeed = speed * speedMultiplicator;
var transformedRealInputAxis = transform.TransformDirection(realInputAxis);
playerRigidbody.MovePosition(transform.position + transformedRealInputAxis * realSpeed * Time.deltaTime);
if(Input.GetButtonDown("Jump") && grounded){
playerRigidbody.AddForce(Vector3.up * jumpForce * 25, ForceMode.Impulse);
}
var hitColliders = Physics.OverlapSphere(check + transform.position, groundSphereRadius, groundLayers);
if(hitColliders.Length == 0){
grounded = false;
}else{
grounded = true;
}
//Fake friction
var easeVelocityFactor : float;
easeVelocityFactor *= 0.75;
playerRigidbody.velocity.x = easeVelocityFactor;
playerRigidbody.velocity.z = easeVelocityFactor;
}
function Update () {
}
function OnDrawGizmosSelected() {
if(debugCollision){
if(grounded){
Gizmos.color = Color.green;
}else{
Gizmos.color = Color.red;
}
Gizmos.DrawSphere(check + transform.position, groundSphereRadius);
}
}
Answer by NGC6543 · Dec 28, 2015 at 12:53 AM
Hey @Bryckout, I guess your character doesn't glitch on a flat terrain, does it? Maybe the glitch is caused by low physics iterations, or, 'resolutions.' How about increasing it?
Go to Edit>project settings>physics then increase the Solver Iteration Count.
See if any change occurs. But increasing the solver iteration comes with the price of computational burden, so do it wisely. And terrain seems to be unreliable when in steep angle, probably due to the resolution, but that's only my guess.
Okay thanks for you're anwser, so like you told me, i increased the 'Solver Iteration Count':
7 : same
8 : same
25 : same but less often
100 : same than 25
So i saw it didn't work so i increase the terrain quality 1024 to 2048
1024 : same
2048 : my pc crashed
$$anonymous$$y PC can't handle it :c But if you want to test it : https://mega.nz/#!xht0hTrb!09A5XsLF$$anonymous$$$$anonymous$$FScC4wLuJv4D9V9Oie5mXzEwazGEzY6$$anonymous$$U
Oh, I just remembered that high gravity setting also causes that phenomenon. $$anonymous$$aybe not your case, though, because it makes objects jitter even when they are on a flat terrain.
Your answer
Follow this Question
Related Questions
Kill player when hit Groung (JavaScript) 1 Answer
How can I make my truck drive on terrain and on bridge 1 Answer
Collision with Terrain 2 Answers
Raycast to Terrain (Conditional Statements) 1 Answer
Can't crash airplane into ground 4 Answers