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 Brizz104 · Sep 19, 2012 at 05:18 AM · collisionraycastcollidertriggerparenting

Help with collision detection with specific colliders

Okay, so here's the deal. I want to create some wall running scripts. The way I want to go about it is to have a trigger cube parented to my fps controller in the front, and one on each side. If the front cube collides with a trigger object with the tag of "wall" then the player moves up. If the side cubes collide with the "wall" then run forward. The side triggers and code aren't here yet because i have a problem. The collision seems to be happening with the fps controller, not the trigger cube. If i run into the wall, no matter what direction i'm facing, the wall triggers a hit. I want it to work so that if i face away from the wall, there is no collision. Only when the trigger cube, (which again is positioned just in front of my character, parented to the fps controller), touches the wall should there be collision.

Here is the code attached to the trigger cube:

 #pragma strict
 
 var playerState : String = "NoWall";
 
 var character : GameObject;
 
 function Start () {
 
     character = GameObject.FindWithTag("Player");    
 }
 
 function Update () {
 
 var motorScript = transform.GetComponent(CharacterMotor);
 
     if(playerState == "Wall" && CharacterMotor.grounded == false && Input.GetKeyDown("space"))
     {
         Debug.Log("Wall Run");
         playerState = "WallRun";
         character.transform.Translate(0, 10, 0);
     }
     
     if(playerState == "WallRun" && CharacterMotor.grounded == true)
     {
         playerState = "NoWall";
         Debug.Log("Nowall");
     }
     
     Debug.Log(playerState);
 }
 
 function OnTriggerEnter(collisionInfo : Collider)
 {        
     if(collisionInfo.gameObject.tag == "wall")
     {
         Debug.Log("Wall Hit");
         playerState = "Wall";
     }    
 }
 
 function OnTriggerExit(collisionInfo : Collider)
 {
     if(collisionInfo.gameObject.tag == "wall")
     {
         Debug.Log("Wall Leave");
         playerState = "NoWall";
     }
 }

So again, i have a wall with normal collision. I have a duplicate wall with Is Trigger selected and with a tag of "wall". I have a cube, parented to the FPS Controller, set to Is Trigger. I have tried doing a Raycast, but I'm not having any luck there whatsoever. If this whole trigger cube thing isn't even possible the way i'm doing it, then that's my bad. Thanks in advance for any help! Here is the positioning:

alt text

cubetrigger.jpg (52.8 kB)
Comment
Add comment · Show 7
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 justinl · Sep 19, 2012 at 08:05 AM 0
Share

Does this code ever get executed: Debug.Log("Wall Hit");

avatar image Brizz104 · Sep 19, 2012 at 09:52 AM 0
Share

Hmmm...it seems that when i tick the answer, a message comes up saying that the question already has an accepted answer, and to remove the accepted status of the other one....but there isn't another answer. Sorry, this is my first time using this system so, even though it's not green for me, is it still answered and therefore cleared? Or is there a bug that isn't letting me untick an answer that isn't here...

avatar image whydoidoit · Sep 19, 2012 at 10:04 AM 0
Share

Oh that's wacky - yeah - there is no accepted answer here. You should just be able to click the tick under my answer below and it should go green.

avatar image whydoidoit · Sep 19, 2012 at 10:05 AM 0
Share

You are right - my magic "mark this answer" button I get for having so much $$anonymous$$arma also says that there is already an accepted answer - must be a bug in UA.

avatar image Brizz104 · Sep 19, 2012 at 10:06 AM 0
Share

is there a way to contact a mod to fix it? i don't want to clutter the forums but it seems to be some sort of error.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by whydoidoit · Sep 19, 2012 at 07:05 AM

The FPS is considering the child boxes to be part of itself because they don't have a rigidbody attached. Attach rigidbodies to the game objects with the colliders and set isKinematic = true.

Comment
Add comment · Show 2 · 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 Brizz104 · Sep 19, 2012 at 08:50 AM 0
Share

whydoidoit! That worked! I thought the Character Controller was a physics replacement for rigidbody, not something different. I put a rigidbody on the FPS Controller and now it works! Thank you both very much for you time and quick responses. justinl: just for closure the Debug.Log does indeed show the "Wall Hit", in case you still wanted to know. Thanks again buds!

avatar image justinl · Sep 19, 2012 at 09:57 AM 0
Share

Hey Brizz104, if $$anonymous$$ike's answer is correct, please indicate his answer as the correct answer by accepting it (top left of the question). Cheers!

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

Prevent shooting when gun is inside wall 1 Answer

Overlap point of 2 kinematic colliders 1 Answer

Receiving information about getting hit by a Raycast 2 Answers

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

Surface with hole and Raycast - Which collider 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