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
1
Question by yohnazo · Jan 03, 2015 at 06:10 PM · collisioncharacter controllerstatic

How do I script a script to put on a static game object, to detect when the character controller is colliding with it?

I have my Character Controller, it has a script on it which does a few things and all works fine, however I need to code it so that it works when the Script is on the static game object and not the character controller.

The problem I have ran in to is with the Collision, I have made it work, to an extent, with OnTriggerEnter after making the static game object an isTrigger, though of course the character controller falls through it.

For now I am going to try and create an alternative method but any help would be greatly appreciated :)

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Mmmpies · Jan 03, 2015 at 06:38 PM

OnTriggerEnter is used if the collider on your object is a trigger.

Try unticking the is trigger and use OnCollisionEnter instead if the issue is that you actually want it to collide.

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 yohnazo · Jan 03, 2015 at 09:12 PM 0
Share

I actually have found a different solution to my problem, however the answer to this specific problem would still be useful to know.

$$anonymous$$mmpies, thanks for the answer, though from what I understand OnCollisionEnter only works if the object that the script is attached to is moving, for a static object it is not colliding with anything, just being collided with.

avatar image Mmmpies · Jan 03, 2015 at 09:29 PM 0
Share

OnCollisionEnter = OnTriggerEnter

OnCollisionStay = OnTriggerStay

OnCollisionExit = OnTriggerExit

If you were using OnTriggerEnter but not colliding was a problem then OnCollisionEnter is the solution.

If that isn't the solution then can you clarify the issue and how you fixed it, it might help someone else which is what Unity Answers is all about.

Really if you think we've answered your question then click that it's answered and if you have a different answer then post your solution so other people can benefit.

I'm not complaining, I don't really care about karma points but just try and make this a question that has an answer so it helps others.

avatar image yohnazo · Jan 04, 2015 at 01:05 AM 0
Share

Hey, yeah that's a good idea.

I haven't found the solution to this question, however I found the solution to my problem.

Say I have platform A, platform B, door A and door B. I want door A to open when I am standing on Platform A, and door B to open when I am standing on platform B. Though it was a bit more complicated than that.

Reasonably easily I can write a script for each and attach them to my character controller, however I do not want to crowd my character controller with a lot of scripts.

So I decide to put the scripts of the platforms ins$$anonymous$$d, however I could not make the platform detect the Collision with the character controller, which is where this question was created, the solution above I am fairly certain I have tried before but I will test it again soon. It would be good for everyone to know.

What I ended up doing, was create one script on the character controller, this would then would then get component the script on the collided object upon collision, and set a boolean in the script to true, after storing the collided game object, I could then set the boolean to false using a similar method when colliding with another gameObject. Everything for the scripts already attached to the gameObjects was of course already in place to work.

The script ended up like this:

 sing UnityEngine;
 using System.Collections;
 
 public class PlatSlide$$anonymous$$aster : $$anonymous$$onoBehaviour {
 
     private PlatformSlideStatic PlatRef;
 
     private PlatformSlide$$anonymous$$ove $$anonymous$$oveRef;
 
     public bool elseWhere;
 
     GameObject Platform;
 
     // Use this for initialization
     void Start () {
         elseWhere = true;
     }

     void OnControllerColliderHit (ControllerColliderHit warp)
     {
 

         if (warp.gameObject.name == "WarpPlat")
         {
 
             Platform = warp.gameObject;
 
             PlatRef = Platform.GetComponent<PlatformSlideStatic> ();
 
             PlatRef.OnWarpPlatform = true;
 
             elseWhere = false;
 

         }
         
         else if (warp.gameObject.name == "CollPlatform")
         {
             elseWhere = true;
             PlatRef = Platform.GetComponent<PlatformSlideStatic> ();
             PlatRef.OnWarpPlatform = false;
 
             $$anonymous$$oveRef = warp.gameObject.GetComponent<PlatformSlide$$anonymous$$ove>();
             $$anonymous$$oveRef.ToEnd();
         }
         
         else if (elseWhere == false)
         {
             elseWhere = true;
             PlatRef = Platform.GetComponent<PlatformSlideStatic> ();
             PlatRef.OnWarpPlatform = false;
         }
         
     }
 
 }


 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Creating custom character controller collision checking 0 Answers

empty object with player controller attached isnt detecting collisions 2 Answers

how to correctly check for a collision with a character controller 1 Answer

2D Character suddenly stops moving for no given reason 1 Answer

Character Controller strange collision bug 2 Answers


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