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 swastika_pallai · Nov 13, 2020 at 12:12 PM · unity 5collider

why does my character passes through trees ??

i know that this question has been asked multiple times...so sorry, and i even saw all the solutions over the net. but nothing worked out for me.. i have a terrain, a tree and a character. howerver, the chararcter passes through the tree. i have applied capsule collider to both of them...but still nothing works... :( can anyone pls say how can i resolve this problem.. its very annoying... thnx in advance..

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by yuvaansh · Nov 13, 2020 at 12:23 PM

@swastika_pallai

I think that the collider is marked as trigger. If it is not set as trigger then I think that your "Player" has a Rigidbody component attached to it. So, I think that you are using transform to move your Player instead of that use rigidbody.position.

I hope this will answer your question ;^)

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 swastika_pallai · Nov 13, 2020 at 12:32 PM 0
Share

the character doesn't has a RigidBody, and there is a line of code which moves it forward..

  transform.Translate(Vector3.forward * (speed) * Time.deltaTime);

Should i change it?? if so... can u pls tell me what should i write...coz i am new to unity.

avatar image yuvaansh · Nov 13, 2020 at 12:42 PM 0
Share

@swastika_pallai
$$anonymous$$aybe a public property is there in the code but it is not assigned. So, the code after that sound is used will not run maybe that's why it won't collide.

I hope this would help 8D

avatar image swastika_pallai yuvaansh · Nov 13, 2020 at 01:08 PM 0
Share

can u say what should i do??? and can u say what does that mean?? i am very new to unity here i have shared the screenshot of the inspector of the tree and the player... player:-alt text

and the tree:- alt text

screenshot-2020-11-13-185557.png (40.3 kB)
screenshot-2020-11-13-185537.png (97.3 kB)
avatar image
0

Answer by yuvaansh · Nov 13, 2020 at 01:40 PM

@swastika_pallai
Now I understand what's the problem. If anything is colliding with other object one of those objects should have a Rigidbody component so you can add the component and configure it. I hope now the bug is fixed ;-D

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 swastika_pallai · Nov 13, 2020 at 02:08 PM 0
Share

now i have added a mesh collider, capsule collider and a terrain collider.. and i have sent a screenshot of what is happening...alt text

and after editting, the inspector of bith the character and the tree is like this:- alt text

after looking at its result, i think there might be some issues in the code.. so i have pasted them too... there are two files, one for movement and one for the camera..

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class camera_controller : $$anonymous$$onoBehaviour
 {
     public enum RotationAxis
     {
         $$anonymous$$ouseX = 1,
         $$anonymous$$ouseY = 2
     }
 
     public RotationAxis axes = RotationAxis.$$anonymous$$ouseX;
 
     public float $$anonymous$$imumVert = -5.0f;
     public float maximumVert = 35.0f;
 
     public float sensHorizontal = 10.0f;
     public float sensVertical = 10.0f;
 
     public float _rotationX = 0;
 
     // Update is called once per frame
     void Update()
     {
         if (axes == RotationAxis.$$anonymous$$ouseX)
         {
             transform.Rotate(0, Input.GetAxis("$$anonymous$$ouse X") * sensHorizontal, 0);
         }
         else if (axes == RotationAxis.$$anonymous$$ouseY)
         {
             _rotationX -= Input.GetAxis("$$anonymous$$ouse Y") * sensVertical;
             _rotationX = $$anonymous$$athf.Clamp(_rotationX, $$anonymous$$imumVert, maximumVert); //Clamps the vertical angle within the $$anonymous$$ and max limits (45 degrees)
 
             float rotationY = transform.localEulerAngles.y;
 
             transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
         }
     }
 }

and

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class NewBehaviourScript : $$anonymous$$onoBehaviour
 {
     public float speed = 100.0f;
 
     private CharacterController _charCont;
 
     // Use this for initialization
     void Start()
     {
         _charCont = GetComponent<CharacterController>();
     }
 
     // Update is called once per frame
     void Update()
     {
         transform.Translate(Vector3.forward * (speed) * Time.deltaTime);
     }
 }


screenshot-2020-11-13-195022.png (64.9 kB)
screenshot-2020-11-13-195035.png (49.8 kB)
avatar image
0

Answer by President · Nov 13, 2020 at 01:43 PM

If you are not using a Rigid Body for you your Character, then it needs to have "Character Controller", that's the first thing.

Second thing, I can see that the Height in your tree Capsule Collider is 0, that is wrong too. The collider should cover the height of the tree. However, a better way to do it to add mesh collider to your tree instead of capsulate collider.

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 swastika_pallai · Nov 13, 2020 at 02:09 PM 0
Share

now i have added a mesh collider, capsule collider and a terrain collider.. and i have sent a screenshot of what is happening...alt text

and after editting, the inspector of bith the character and the tree is like this:- alt text

after looking at its result, i think there might be some issues in the code.. so i have pasted them too... there are two files, one for movement and one for the camera..

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class camera_controller : $$anonymous$$onoBehaviour
 {
     public enum RotationAxis
     {
         $$anonymous$$ouseX = 1,
         $$anonymous$$ouseY = 2
     }
 
     public RotationAxis axes = RotationAxis.$$anonymous$$ouseX;
 
     public float $$anonymous$$imumVert = -5.0f;
     public float maximumVert = 35.0f;
 
     public float sensHorizontal = 10.0f;
     public float sensVertical = 10.0f;
 
     public float _rotationX = 0;
 
     // Update is called once per frame
     void Update()
     {
         if (axes == RotationAxis.$$anonymous$$ouseX)
         {
             transform.Rotate(0, Input.GetAxis("$$anonymous$$ouse X") * sensHorizontal, 0);
         }
         else if (axes == RotationAxis.$$anonymous$$ouseY)
         {
             _rotationX -= Input.GetAxis("$$anonymous$$ouse Y") * sensVertical;
             _rotationX = $$anonymous$$athf.Clamp(_rotationX, $$anonymous$$imumVert, maximumVert); //Clamps the vertical angle within the $$anonymous$$ and max limits (45 degrees)
 
             float rotationY = transform.localEulerAngles.y;
 
             transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
         }
     }
 }

and

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class NewBehaviourScript : $$anonymous$$onoBehaviour
 {
     public float speed = 100.0f;
 
     private CharacterController _charCont;
 
     // Use this for initialization
     void Start()
     {
         _charCont = GetComponent<CharacterController>();
     }
 
     // Update is called once per frame
     void Update()
     {
         transform.Translate(Vector3.forward * (speed) * Time.deltaTime);
     }
 }


screenshot-2020-11-13-195022.png (64.9 kB)
screenshot-2020-11-13-195035.png (49.8 kB)
avatar image President swastika_pallai · Nov 13, 2020 at 02:33 PM 0
Share

You don't need 2 colliders, one will do the job. Either "$$anonymous$$esh Collider" or "Capsule Collider". Let me break it down for you (The better way). Looking at your "$$anonymous$$esh Collider", your "$$anonymous$$esh" says "None ($$anonymous$$esh)". That means you don't have a mesh identified, and your mesh collider will do nothing, as if it doesn't exist. So if your tree has a mesh, you need to put it in the "$$anonymous$$esh" field, if it doesn't, I suggest that you find or create another tree that has a mesh collider.

avatar image swastika_pallai President · Nov 14, 2020 at 05:24 AM 0
Share

now i have added a mesh but still.... here's a screenshot.. alt text

and here i have shared the full inspector of the tree and the player..alt text

alt text

screenshot-2020-11-14-104840.png (22.1 kB)
screenshot-2020-11-14-105108.png (22.0 kB)
avatar image
0

Answer by yuvaansh · Nov 13, 2020 at 02:33 PM

@swastika_pallai On the mesh collider check the convex option. That will inform the mesh collider to take the most possible shape of that object.

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 swastika_pallai · Nov 14, 2020 at 05:55 AM 0
Share

tried.... nothing happened

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

281 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Tilemap Collider 2D 2 Answers

Unity 5 - Cloth falling through floor 0 Answers

Mesh Collider didn't work unless i walk slowly towards it 1 Answer

Climbing using OnTriggerEnter and Arrow Keys? 1 Answer

Problems with raycast accuracy 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