Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by OrdinaryDev83 · Dec 27, 2015 at 09:10 PM · javascriptcollisionterrain

Terrain Collision Glitch

I created a terrain and i added my player prefab.

That done this : link text 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);
     }
 }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image OrdinaryDev83 · Dec 28, 2015 at 09:03 AM 0
Share

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

avatar image NGC6543 OrdinaryDev83 · Dec 28, 2015 at 11:08 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

43 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges