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
1
Question by arisonu123 · Jul 29, 2017 at 06:03 PM · collisioncollidercollision detectionridgidbody

Collision does not work, player can walk through walls

So I have a character with a non-kinematic rigidbody that does not use gravity. The character also has a box collider around it that is not a trigger. My character is walking along a plane with a mesh collider, turning on gravity does not cause them to fall. I am trying to put box colliders along the sides of the plane to stop my player from walking off. I have tried both using root motion for movement of my player/character as well as using translate and rotations on the transform of my player. I most recently tried a character controller to see if it would make any difference but to no avail.

I have a debug print out for the collison. The player collides according to the debug log in my oncollisionenter but is able to walk right through the wall out into oblivion. How do I get collision to work? My player is able to walk through my invisible wall boundaries, trees, enemies, everything. I have also tried discrete, continuous, and continuous dynamic on the rigidbody. I just want my character to not be able to move through colliders and be forced to move around them or walk back from the world boundaries.

My current movement code for those asking:

 [SerializeField]
 public float speed=2f;
 [SerializeField]
 private float defaultSpeed = 2f;

 [SerializeField]
 private Transform playerGraphic;
   
 private Animator controller;
 
 private void Start{
    controller = this.gameObject.GetComponent<Animator>();
 }
 
 private void Update() {
     if (!controller.GetBool("dead"))
     {
              Movement();
              if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.S))
             {
                 controller.SetBool("walk", true);
             }
            
       }
 }
 private void Movement()
 {
 
         //Player object movement
         float horMovement = Input.GetAxisRaw("Horizontal");
         float vertMovement = Input.GetAxisRaw("Vertical");
 
 
         if (horMovement != 0 && vertMovement != 0)
         {
             speed = defaultSpeed - .5f;
                        
 
         }
         else
         {
             speed = defaultSpeed;
 
         }
         transform.Translate(transform.right * horMovement * Time.deltaTime * speed);
         transform.Translate(transform.forward * vertMovement * Time.deltaTime * speed);
         
         //Player graphic rotation
         Vector3 moveDirection = new Vector3(horMovement, 0, vertMovement);
         if (moveDirection != Vector3.zero)
         {
             Quaternion newRotation = Quaternion.LookRotation(moveDirection);
             playerGraphic.transform.rotation = Quaternion.Slerp(playerGraphic.transform.rotation, newRotation, Time.deltaTime * 8);
 
         }
     }


Comment
Add comment · Show 3
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 tanoshimi · Jul 29, 2017 at 06:23 PM 0
Share

What's the actual movement code you're using? Clearly if you're setting transform.position directly then you're not giving the physics engine chance to react to the collision. Have you tried setting the rigidbody velocity ins$$anonymous$$d?

avatar image arisonu123 tanoshimi · Jul 30, 2017 at 02:35 AM 0
Share

Hi @tanoshimi ! I have posted my code above. I am using translate for movement and am setting the rotation directly. I have not tried setting the rigidbody velocity ins$$anonymous$$d. I can try that and see if it helps.

avatar image arisonu123 arisonu123 · Jul 30, 2017 at 08:00 PM 0
Share

Welp @tanoshimi , I tried setting the velocity for movement ins$$anonymous$$d of using translate, still does not work.

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Ratchet_Ritz · Jul 29, 2017 at 09:49 PM

do the walls have colliders?

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 arisonu123 · Jul 30, 2017 at 02:32 AM 0
Share

$$anonymous$$y walls definitely have colliders. I put debug log code in both the OnCollisionEnter and OnCollisionExit. Both of them get triggered as I hit and then walk through and out of my walls. Same goes for my enemies and the trees in my game.

avatar image
0

Answer by TheSOULDev · Jul 29, 2017 at 10:54 PM

Perhaps you're moving too quickly for the fixed delta time. Try changing the time step by going into

Edit -> Project Settings -> Time

and changing the Fixed Timestep to maybe 0.01 (100 FPS). If that doesn't work, something's wrong with your colliders.

EDIT: Also make sure that Is Trigger is unchecked with colliders you want to stop your player.

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 arisonu123 · Jul 30, 2017 at 07:59 PM 0
Share

@TheSOULDev I tried this and sadly it doesn't work either. As for the fps I'm getting, it is probably more around 25,30(really need a new graphics card and computer in general). I tried changing it 0.03 as well as 0.01, no difference. isTrigger is not checked on anything I am trying to get to stop my player.

avatar image
0

Answer by PersianKiller · Jul 30, 2017 at 03:38 AM

I think that's because of that your moving your character with transform.Translate when you use it your collider won't collision with others change it to GetComponent().velocity = new Vector2 (MoveSpeed*Input.GetAxisRaw("Horizontal"),GetComponent().velocity.y); it might help you.

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 arisonu123 · Jul 30, 2017 at 07:43 PM 0
Share

@Persian$$anonymous$$iller This still doesn't work. I am able to have my player move this way, but it still walks right through colliders. I tried doing all of the movement in fixed update and I tried changing the speed as well, still does not work. I also tried changing the settings on the rigidbody for collision. I tried discrete, continuous, continuous dynamic, no difference. I honestly don't know what to do.

avatar image amybuc95 arisonu123 · Nov 16, 2019 at 06:30 AM 0
Share

Hi!! Really sorry to resurrect a very old question, but did you manage to get this fixed? I'm in the exact same position with the same issue at the moment, and there's only so many times I can hear people say "have you added a collider to your walls?" before I lose my $$anonymous$$d completely :)

avatar image Ermiq amybuc95 · Nov 16, 2019 at 02:05 PM 0
Share

Check out physics collision matrix in Edit->ProjectSettings->Physics->Scroll down. You have to have the crossing between layers of the player and the walls to be checked.

avatar image
0

Answer by Abirami-Govindarajan · Jul 31, 2017 at 07:07 AM

I understand your player movement is through character controller. So now I want you to try adding mesh collider component to your walls. Make sure you check on "Convex" option in the mesh collider. If your walls have a box collider, also check on "Is Trigger" option in it. Try it and let me know if this worked.

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

115 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

Related Questions

How to make arrow stick to environment ? 3 Answers

Best collision detection method? 2 Answers

Physic based golf game - ball bouncing off the connection of colliders on flat surface 2 Answers

Why doesn't my prefab collide with my map? 1 Answer

Detect collision point?? 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