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 Chenab · Mar 23, 2013 at 03:59 AM · gravitycharacter controllerbox collider

My character controller falls through a box collider

I'm admittedly new to this... anyway my issue is that the object I use for my character uses a character controller and my ground objects use box colliders. I start my character object several meters above the ground by it falls through the box collider every time. I've made the gravity very small in an attempt to counteract this and made my box collider much bigger, neither helped.

 using UnityEngine;
 using System.Collections;
 
 public class PlayerClass : MonoBehaviour
 {
     private float hspeed = 10f;
     private float vspeed = 0F;
     private float gravity = 1F;
     private float test = 0;
     private Vector3 moveDirection = Vector3.zero;
     private float hdirection;
     public bool isaccending=true;
     private float movspeed=0;
 
     // Use this for initialization
     public float movementSpeed = 10;
     public float turningSpeed = 60;
     void Start(){
         
     
     }
     void Update() {
         CharacterController controller = GetComponent<CharacterController>();
         float horizontal = Input.GetAxis("Horizontal") * turningSpeed * Time.deltaTime;
         transform.Rotate(0, horizontal, 0);
         float vertical = Input.GetAxis("Vertical") * movementSpeed * Time.deltaTime;
         transform.Translate(-vertical, 0, 0);
         float strafe = Input.GetAxis("Strafe")* movementSpeed * Time.deltaTime;
         transform.Translate(0, 0, strafe);
         isaccending=controller.isGrounded;
         if(controller.isGrounded){
             vspeed =0;
             
         }else{
             vspeed-=gravity* Time.deltaTime;
         }
         transform.Translate(new Vector3(0,vspeed,0));
         
     }
     
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Omir · Mar 23, 2013 at 06:21 AM

Make Sure You Check Following things : You have added Capsule Collider or Character controller to player You added rigidbody to player Script is not accessing any rigidbody or character controller component and changes it on Runtime Mesh colider you have added to box is checked at top bar Check these and come back if Helped #meer #opkashmir

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 Owen-Reynolds · Mar 23, 2013 at 02:14 PM 0
Share

character controllers shouldn't have rigid bodies, meshColliders or capsule colliders (they get a collider automatically, so you don't need to add one.)

rigidbodies are made to automatically move you. Since the charCont already has a movement script, adding an RB makes it so two things are fighting to move it, which makes it all twitchy.

You can use an RB+collider, not have a charController, then use a different script that "pushes" using AddForce.

avatar image
0

Answer by Owen-Reynolds · Mar 23, 2013 at 02:14 PM

Transform.translate is purposely made to ignore collisions. It will move you through walls, etc... . Use controller.Move instead (lots of places here to find movement scripts using it.)

Turns out that checking for obstacles and figuring out the correct way to slide around any slanted walls you ram, that takes a lot more work than just moving. translate just moves, same as using the Inspector to move (translate is the actual math term for sliding something.) controller.move has all of that extra "is there a box below me?" checking built in.

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 Chenab · Mar 23, 2013 at 04:41 PM 0
Share

I wasn't aware of that, thank you.

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

12 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

Related Questions

CharacterController.Move uses gravity even though it shouldn't 1 Answer

Character floats upward when looking up and down 0 Answers

Character Controller walking on the inside of a cylinder. 0 Answers

Collision between Character Controller and Box Collider 2 Answers

Non Capsule Character Controller? 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