Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TheLinkingTinker · Apr 02, 2014 at 04:12 AM · collisionphysicsrigidbodycharactercontrolleraddforce

Physics AddForce reduced when 3 objects are colliding

I am Going through ETeeskiTutorials fps and I am just finnishing up the Rigid body character controller movement script and I have run into a problem. When my character is running around everything seems to be happening as it should, but when the character is touching 2 seperate surfaces (like the floor and a wall, or the seam where two diffrently angled floors are touching) I notice a dramatic reduction in the addition of force to the character. Most noticeably when jumping. Here are the Scripts I am using.

This one is for Camera look:

 var lookSensitivity : float = 5;
 @HideInInspector
 var yRotation : float;
 @HideInInspector
 var xRotation : float;
 @HideInInspector
 var currentYRotation : float;
 @HideInInspector
 var currentXRotation : float;
 @HideInInspector
 var yRotationV : float;
 @HideInInspector
 var xRotationV : float;
 var lookSmoothDamp : float = 0.045;
 
 function Update () {
     yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
     xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
     
     currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp);
     currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp);
     
     xRotation = Mathf.Clamp(xRotation, -90, 90);
     
     transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0);
 }

and this one is for movement and jumping:

 var walkAcceleration : float = 45;
 var runDeceleration : float = 1;
 var walkDecelerationVolX : float;
 var walkDecelerationVolZ : float;
 var walkDeceleration : float = 0.5;
 var cameraObject : GameObject;
 var maxWalkSpeed : float = 3;
 var horizontalMovement : Vector2;
 var jumpVelocity : float = 300;
 var grounded : boolean = false;
 var maxSlope : float = 60;
 
 function Update () 
 {
 
 //faces the rigidbody with the camera//
     transform.rotation = Quaternion.Euler(0, cameraObject.GetComponent(MouseLookScript).currentYRotation, 0);
 
 //gets current speed as a Vector2//
     horizontalMovement = Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
     //sets a percentage that is inversely proportional to the speed over maxWalkSpeed//
     if(horizontalMovement.magnitude > maxWalkSpeed)
     {
         runDeceleration = maxWalkSpeed / horizontalMovement.magnitude;
     } 
     //Keeps runDecceleration from getting stuck at a low percentage in the event of sudden decceleration//
     else
     {
         runDeceleration = 1;
     }
     
     walkDeceleration = horizontalMovement.magnitude / 25 + 0.1;
     //dampend character slide//
     if(grounded)
     {
         rigidbody.velocity.x = Mathf.SmoothDamp(rigidbody.velocity.x, 0, walkDecelerationVolX, walkDeceleration);
         rigidbody.velocity.z = Mathf.SmoothDamp(rigidbody.velocity.z, 0, walkDecelerationVolZ, walkDeceleration);
     }
     
     //wasd movement//
     rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * runDeceleration, 0, Input.GetAxis("Vertical") * walkAcceleration * runDeceleration);
     
 //Jumping//
     if(Input.GetButtonDown("Jump") && grounded)
     {
         rigidbody.AddForce(0, jumpVelocity, 0);
     }
     
 
 }
 //Jumping Prerequisits//
 function OnCollisionStay(collision : Collision)
 {
 
     for(var contact : ContactPoint in collision.contacts)
     {
         if(Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
         {
             grounded = true;
         }
     }
 }
 
 function OnCollisionExit()
 {
     grounded = false;
 }

I am not sure if it is just a quark with the physics engine adding the friction in a funny way when dealing with this situation or if I am approaching the code in a weird way. I have kind of done a bit of modification of it from the original tutorial. Any ways any insight into this anomaly would be greatly appreciated, thanks. :)

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 TheLinkingTinker · Apr 02, 2014 at 07:32 AM

OK, after a little research I found that some of the other posts here where dealing with the same problem. With a bit of experimentation I found that rigid bodies behave strangely when in contact with none rigid bodies. It just seems to be a quark in the physics engine. The answer I found is that if you are going to have a rigid body character controller then everything that character comes in contact with must also be a rigid body; the ground, the walls, the other characters. don't forget to set any rigid bodies that intersect to kinematic or some other strange effects will occur. Now my ground and walls are rigid bodies and have kinematic checked and all the freeze position and freeze rotation boxes checked. The problem is now gone... although I can't help but wonder if having every object as a rigid body may be a bit resource intensive.

Comment
Add comment · 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

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

20 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

Related Questions

Addforce to ball in camera position 0 Answers

Is it ok to move objects with CharacterControllers not through their CharacterController and without adding a kinematic Rigidbody? 1 Answer

Character Controller meets Rigidbody 1 Answer

Prevent rigidbody being affected by character controller 2 Answers

How to change CC script to Rigidbody script 1 Answer


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