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 MadJohny · Dec 06, 2013 at 07:05 PM · movementphysicsrigidbodycharactercontroller

Turning a rigidbody controller into a character controller (almost)

Hi, in my game I am using a rididbody controller instead of a character controller for some reasons, the thing is that the way a rigidbody contrller interacts with other objects is completily different, I prefer my rigidbody controller compared to my character controller, but at the same time I feel that the rigidbody controller has too much physics in it, for example it bounces alot when it goes against objects, I want it to basically have no interaction with other objects, but still be a rigidbody, anyone can tell me a good way to make a rigidbody kinda physicless and not so bouncy (I already have a custom physic material that has everything set to 0, even friction, maybe I should tune up the friction a little bit, but that way sometimes it gets like too slow when colliding with walls)

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 Raiden-Freeman · Dec 07, 2013 at 12:40 AM

I think it would be better if you kept it as a rigidbody and made it kinematic, so that other objects interact with it, but the character controller overrides the physics. How do you move the character? By applying force?

You can also see how they did it in many Unity examples (by Unity themselves), as most of their characters are rigidbodies (even in the 2d example).

Comment
Add comment · Show 3 · 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 MadJohny · Dec 07, 2013 at 10:41 AM 0
Share

setting it as kinematic won't let it move, this is my movement script:

 using UnityEngine;
 using System.Collections;
 
 public class Player$$anonymous$$ovementScript : $$anonymous$$onoBehaviour {
 
     public float $$anonymous$$ovement;
     float walkAcceleration = 1600f;
     public float walkAccelAirRatio = 0f;
     public float walkDeAcceleration = 0.3f;
     [HideInInspector]
     public float walkDeAccelerationVolx;
     [HideInInspector]
     public float walkDeAccelerationVolz;
     public int accelerationController = 1;
 
     public GameObject cameraObject;
     float maxWalkSpeed = 10f;
     public Vector2 horizontal$$anonymous$$ovement;
 
     static bool grounded = false;
     public float maxSlope = 60f;
 
     void FixedUpdate (){ 
         
         horizontal$$anonymous$$ovement = new Vector2(rigidbody.velocity.x, rigidbody.velocity.z);
         
         if(horizontal$$anonymous$$ovement.magnitude > maxWalkSpeed){
             horizontal$$anonymous$$ovement = horizontal$$anonymous$$ovement.normalized;
             horizontal$$anonymous$$ovement *= maxWalkSpeed;
         }
         
         rigidbody.velocity = new Vector3(horizontal$$anonymous$$ovement.x,rigidbody.velocity.y,horizontal$$anonymous$$ovement.y);
         
         if(grounded){
             float temp1x = $$anonymous$$athf.SmoothDamp(rigidbody.velocity.x, 0, ref walkDeAccelerationVolx, walkDeAcceleration);
             float temp2z = $$anonymous$$athf.SmoothDamp(rigidbody.velocity.z, 0, ref walkDeAccelerationVolz, walkDeAcceleration);
             rigidbody.velocity = new Vector3 (temp1x,rigidbody.velocity.y, temp2z);
         }
             
         
         transform.rotation = Quaternion.Euler(0f, cameraObject.GetComponent<$$anonymous$$ouseLookScript>().currentYRotation, 0f);
     
         if (grounded)
             rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * Time.deltaTime);
         else
             rigidbody.AddRelativeForce(Input.GetAxis("Horizontal") * walkAcceleration * walkAccelAirRatio * Time.deltaTime, 0, Input.GetAxis("Vertical") * walkAcceleration * walkAccelAirRatio* Time.deltaTime);        
     }
     
     void OnCollisionStay (Collision collision)
     {
         foreach (ContactPoint contact in collision.contacts){
             if (Vector3.Angle(contact.normal, Vector3.up) < maxSlope)
             grounded = true;
         }
     }
     void OnCollisionExit (){
         grounded = false;
     }
 }
avatar image Raiden-Freeman · Dec 09, 2013 at 12:38 AM 0
Share

http://docs.unity3d.com/Documentation/Components/class-Rigidbody.html At the end of the page is what I meant. Setting it to kinematic and moving it with

 this.transform.translate(Vector3.up

or this.transform.translate(new Vector3(displacementInXAxis,displacementInYAxis,displacementInZAxis ...

If you want to keep using forces, you can I guess. Is your wall's* material bounciness set to 0? Also make sure you're altering the bounciness of the Collider component's material, not Rigidbody's.

*by wall I mean whatever object your character collides with and is bouncing back when you don't want him to.

avatar image MadJohny · Dec 10, 2013 at 05:38 PM 0
Share

In my player physics material I already have bounce combine set to $$anonymous$$imum, shouldn't that do the trick already? Since the $$anonymous$$imum value is 0 (player's bounciness)

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

17 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

Related Questions

Click to move a character in a terrain 1 Answer

How to let a GameObject generate force but not be affected by certain forces? 0 Answers

How not to make a RigidBody not go into ground when tilted foward? 1 Answer

Guidelines for using rigidbody, collider, CharacterControllerScript, etc? 3 Answers

Character Controller meets Rigidbody 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