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 Kensei · Aug 06, 2014 at 05:16 PM · c#collidertriggerlogic

Erratic trigger behavior, I can't find the fault.

Hi guys, I'm kinda at my wits end here. This is my problem:

I have 2 walls opposite of each other. The player can jump off these walls. There is a trigger collider attached to the player object. When the player jumps off one of the walls, this wall becomes "unjumpable" and the opposite becomes "jumpable".

I have this script attached to my player:

 public bool proccedLeft = false;
 public bool proccedRight = false;
 public bool procced = false;
 
 void OnTriggerExit2D (Collider2D other)
     {
         if(procced)
         {
             if(other.tag == "LeftWall")
             {
                 proccedLeft = true;
                 procced = false;
                 Debug.Log ("LeftProc:" + proccedLeft);
             }
             if(other.tag == "RightWall")
             {
                 proccedRight = true;
                 procced = false;
                 Debug.Log ("RightProc:" + proccedRight);
             }
         }
     
     }


Both walls share this script:

 public class WallControl : MonoBehaviour 
 {
 
     public GameObject oppositeWall;
     private Bouncer jumper;
        private Renderer myRend;
     void Start () 
     {
         myRend = renderer;
         myRend.renderer.material.color = Color.green;
         jumper = GameObject.FindGameObjectWithTag("Player").GetComponent<Bouncer>();
     }
 
     void FixedUpdate()
     {
         if(jumper.proccedLeft && tag == "LeftWall")
         {
             gameObject.layer = 13;
             oppositeWall.layer = 9;
             oppositeWall.renderer.material.color = Color.green;
             myRend.material.color = Color.red;
 
             print("LeftGone");
 
             jumper.proccedLeft = false;
             jumper.procced = false;
 
         }
         if(jumper.proccedRight && tag == "RightWall")
         {
             gameObject.layer = 13;
             oppositeWall.layer = 9;
             oppositeWall.renderer.material.color = Color.green;
             myRend.material.color = Color.red;
 
             print ("RightGone");
 
             jumper.proccedRight = false;
             jumper.procced = false;
         }
 
     }


Everything works, but sometimes a procc won't register. In other words the player jumps off a wall, but the wall stays available. This happens irregularly, I have playtested for 1 hour and have found no patterns. Now I know that in order for jump bool to be true, the trigger must return true when next to a wall. So the trigger works fine since I have no problems with other collisions.

I have tried many different solutions up until now. Tried sticking the wall logic in Update and even LateUpdate. Tried putting the trigger collider on a child object of the player. Tried separating the wall code and adding it to an empty game object. The result is the same. I even played around with the physics timestep.

I can't find a logical lapse in my code, so it seems to me on paper everything should be functional. The problem occurs not only at high speeds, but at low ones too.

Edit: This is my movement control code:

 void FixedUpdate ()
     {    
 
         float ms = Input.GetAxis ("Horizontal");
 
         // If the player is changing direction (ms has a different sign to velocity.x) or hasn't reached maxSpeed yet...
         if(ms * rigidbody2D.velocity.x < maxSpeed)
             // ... add a force to the player.
             rigidbody2D.AddForce(Vector2.right * ms * moveSpeed);
         
         // If the player's horizontal velocity is greater than the maxSpeed...
         if(Mathf.Abs(rigidbody2D.velocity.x) > maxSpeed)
             // ... set the player's velocity to the maxSpeed in the x axis.
             rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * maxSpeed, rigidbody2D.velocity.y);
 
 
 
         if(jump)
         {    
 
             //If condition from update is met, jump and then reset the condition to false.
             rigidbody2D.AddForce (new Vector2 (gtfo,jumpForce) * comboJumps/2);
             jump = false;
 
 
             //Prevent the player from abusing the wall.
             if (player.position.x < startPosition.x)
             {
                 if (walled)
                     gtfo = repelForce * 20;
                 else gtfo = repelForce;
                 
 
             }
             if (player.position.x > startPosition.x)
             {
                 if (walled)
                     gtfo = repelForce * 20;
                 else gtfo = -repelForce;
 
             }
         }
 
     }




Comment
Add comment · Show 13
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 Jzmallz · Aug 06, 2014 at 05:20 PM 0
Share

how are you controlling the character are you using its rigidbody2D?

avatar image meat5000 ♦ · Aug 06, 2014 at 05:21 PM 0
Share

Colliders are a bit poo if you move an object through them using .position or Translate.

avatar image Jzmallz · Aug 06, 2014 at 05:23 PM 0
Share

Yes meat is right. If you are moving it using its .position or Transform.translate, then the collisions might be off occasionally. If that is the case I would suggest moving it using its Rigidbody2D.

avatar image Kensei · Aug 06, 2014 at 05:27 PM 0
Share

I'm using rigidbody2D.

avatar image meat5000 ♦ · Aug 06, 2014 at 05:28 PM 0
Share

How are you moving the rigidbody?

Show more comments

1 Reply

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

Answer by Kensei · Aug 07, 2014 at 04:45 PM

OMG I solved it...ridiculous problem. The boolean "procced" was assigned a false value in 2 scripts resulting in biym. Removing jumper.procced = false from the WallControl script solved the issue.

Can't believe it -.-.

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

23 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

Related Questions

Call a Void on Collision 2 Answers

Triggering candle lights on with Colliders 1 Answer

Multiple triggers on one object still a no? 1 Answer

Triggers Interacting with Triggers 0 Answers

I need help with triggers 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