• 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 JMasterBoi · Aug 06, 2020 at 01:58 AM · rigidbodycharacter controller

How to interact with RigidBodies with Character Controller? Unity 3D

In my Unity game, I have a character controller object for the player. However, I have been informed that the character controller doesn't interact with physics objects (rolling a ball, pushing a wall, etc).

I would like to know how to be able to move/interact physically with the PlayerController component.

Comment
Add comment · Show 1
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 Llama_w_2Ls · Aug 06, 2020 at 07:35 AM 0
Share

There are multiple ways to move around using the charactercontroller component. Brackeys tutorials have some really helpful guides on how to set up your FP player controller using the CharacterController. To interact physically with objects is, in my opinion, not that much of a difference to how you interact with objects normally, however, instead of the rigidbody being on the player, you can place the rigidbody onto the object youre trying to interact with.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by zyppi1 · Aug 06, 2020 at 07:59 AM

Try adding collider to him.

Comment
Add comment · Show 1 · 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 JMasterBoi · Aug 07, 2020 at 05:32 AM 0
Share

you cant do that

avatar image
1

Answer by Rambovalle · Dec 22, 2020 at 07:33 PM

@JMasterBoi I had the same problem so I made this you can change the forcemultiplyer to your needs. I hope this is helpful.


using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PhysicsInteract : MonoBehaviour { public float forceMultiplyer = 1000f, velocity; public Vector3 Velocity;

 private Vector3 lastframepos;

 //checks collision
 private void OnControllerColliderHit(ControllerColliderHit collision)
 {
     //checks if there is rigidbody
     if (collision.rigidbody == null) { return; }

     Vector3 pushDir = Velocity;

     //Adds force to the object
     collision.rigidbody.AddForce(pushDir * velocity * forceMultiplyer * Time.deltaTime, ForceMode.Impulse);
 }

 private void Update()
 {
     //calculates velocity
     Velocity.x = transform.position.x - lastframepos.x;
     Velocity.y = transform.position.x - lastframepos.y;
     Velocity.y = transform.position.y - lastframepos.y;

     //calculates velocity "Speed"
     float vx;
     float vy;
     float vz;
     if(Velocity.x < 0) { vx = Velocity.x * -1; } else { vx = Velocity.x; };
     if (Velocity.y < 0) { vy = Velocity.y * -1; } else { vy = Velocity.y; };
     if (Velocity.z < 0) { vz = Velocity.z * -1; } else { vz = Velocity.z; };

     velocity = vx + vy + vz;

     //Sets the lastframe pos
     lastframepos = transform.position;
 }

}

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 Rambovalle · Dec 22, 2020 at 08:30 PM 0
Share

And you can add float $$anonymous$$ass ollision.rigidbody.AddForce(pushDir velocity $$anonymous$$ass force$$anonymous$$ultiplyer Time.de... If you want

avatar image Rambovalle Rambovalle · Dec 22, 2020 at 08:31 PM 0
Share

$$anonymous$$ultiply charackters dont show in comments

avatar image entirelydoomed · Jul 28, 2021 at 01:58 PM 0
Share

I am using similar script, but often rigidbody gets pushed away with some crazy big force even though the actual force passed in AddForce method is not big at all. It must be some collision problem, but this is really crucial and i don't think that simply adding force like that can help achieve smooth consistent collision.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

188 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 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 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 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 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

Rigidbody vs. Character Controller 2 Answers

Ethereal Character Controller 2 Answers

OnCollisionEnter not working between two rigidbodies 1 Answer

How to keep rigidbody from falling through terrain? 2 Answers

Ragdoll driven game 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