Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 izzanfuad · Mar 16 at 06:41 AM · collision detectioncollisions

Help! OnTriggerStay() not working!!!

Help guys! I don't know why, but I have 2 objects in which where if they collide with my cube object the only one that the trigger connects is the capsule one. This capsule is a player in which has player movements for FPS, I tried to copy only the collision part for a cube but it didn't work as intended.

Here's the code for for each one

sphere:

     public bool inrange = false;
 
     public void Inrange()
     {
         inrange = true;
     }
 
     public void Outrange()
     {
         inrange = false;
     }
 

Here's the player:

     // Start is called before the first frame update
     [SerializeField] Transform PlayerCamera = null;
     [SerializeField] float mouseSensitivity = 3.5f;
     [SerializeField] bool LockCursor = true;
     [SerializeField] float MovementSpeed = 6.0f;
     [SerializeField] float Gravity = -13.0f;
     [SerializeField] [Range(0.0f, 0.5f)] float MoveSmoothTime = 0.3f;
     [SerializeField] [Range(0.0f, 0.5f)] float MouseSmoothTime = 0.03f;
     [SerializeField] bool canmove = true;
     public bool inrange = false;
 
     float CameraPitch = 0.0f;
     float VelocityY = 0.0f;
     CharacterController Controller = null;
 
     Vector2 CurrentDirection = Vector2.zero;
     Vector2 CurrentDirVelocity = Vector2.zero;
 
     Vector2 CurrentMouseDelta = Vector2.zero;
     Vector2 CurrentMouseDeltaVelocity = Vector2.zero;
 

     public void Inrange()
     {
         inrange = true;
     }
 
     public void Outrange()
     {
         inrange = false;
     }

And here's the code for the object of collision:

     public void OnTriggerStay (Collider other)
     {
         this.gameObject.GetComponent<Trigger>().enabled = true;
         FindObjectOfType<PlayerController>().Inrange();
         FindObjectOfType<batu>().Inrange();
     }
 
     public void OnTriggerExit (Collider other)
     {
         FindObjectOfType<PlayerController>().Outrange();
         FindObjectOfType<batu>().Outrange();
     }
 

It's the freaking same! Here's the picture for the object inspection

Inspection of Sphere Inspection of Player

As you can see in their inspection script, there's a bool for confirming they are in range of the object or not. But the only one that becomes true is the Player not the Sphere

capture.png (206.9 kB)
capture1.png (202.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 Narc0t1CYM · Mar 16 at 03:42 PM 0
Share

What is colliding with the sphere? Maybe one of the GameObjects that are colliding is missing a RigidBody component.

avatar image izzanfuad Narc0t1CYM · Mar 16 at 03:45 PM 0
Share

It's the same GameObject which is a cube and has a Box Collider, but the strange thing is only the Player got any interaction when colliding (OnTriggerStay() or OnTriggerEnter() ) with the cube but the Sphere in which also jave the RigidBody can't

avatar image izzanfuad Narc0t1CYM · Mar 16 at 03:47 PM 0
Share

And yes before you ask, I actually tried putting a RigidBody in the Sphere but it still won't connect

avatar image Narc0t1CYM Narc0t1CYM · Mar 16 at 03:49 PM 0
Share

Try changing FindObjectOfType<batu>().Inrange(); - and the Outrange() version as well - to GameObject.GetComponent<batu>().Inrange() - and .Outrange()

avatar image izzanfuad Narc0t1CYM · Mar 16 at 03:53 PM 0
Share

So Sphere.getComponent(SphereCode).Inrange() and / or Outrange()?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

137 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

Related Questions

Mesh Colliders and 2D Colliders 1 Answer

OnCollision2D never worked 0 Answers

how to prevent bumping cubes on collision? 1 Answer

Collider/Rigidbody not working as expected 1 Answer

Player registering collisions where there are none 0 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