Triggers only working when game is Maximized on Play

This is quite weird, not sure if its a bug or something I’m doing wrong.

My onTriggerEnter and Exit2D don’t work when I test my game in the smaller game view, only when I “Maximize On Play”

Has anyone else run into an issue like this and perhaps have a fix?

Thanks

Are you using physics correctly? Sounds like you might not be.

With Physics (or Physics2D), never manipulate the Transform directly. If you manipulate the Transform directly, you are bypassing the physics system and you can reasonably expect glitching and missed collisions and other physics mayhem.

Always use the .MovePosition() and .MoveRotation() methods on the Rigidbody (or Rigidbody2D) instance in order to move or rotate things. Doing this keeps the physics system informed about what is going on.

With a wheel collider, use the motor or brake torque to effect motion.

2 Likes

Thanks Kurt, I think that may have fixed it, although i’ll have to rewrite most of my code (but thats okay!)

another quick question

What about with setting a parent?

can i say:

item.transform.SetParent(itemAnchor.transform);

or will this mess with the physics as well? Im also changing the rigidbody to kinematic when doing this.

It’s not going to keep that Rigidbody in place relative to the parent, if that’s what you are expecting.

If you are trying to connect a Rigidbody to that parent, you need some kind of joint, such as a FixedJoint

im using a raycast to see if the player is within reach to an item
Then on a button press, moving that item to the players hand.
so the item will move with the player.

if(player.itemPicked){
item.transform.SetParent(itemAnchor.transform);
item.GetComponent().MovePosition(itemAnchor.transform.position);
item.GetComponent().MoveRotation(itemAnchor.transform.rotation);
item.GetComponent().isKinematic = true;
}

are you saying it would be better for me to attach a fixedjoint to the itemAnchor and then, on button press, attach the item to that fixed joint?

Interesting… I guess it varies by what you’re trying to do. Never thought of parenting it AND driving position rotation… does it work? If so well, I suppose move on! :slight_smile:

yeah it works :slight_smile: thanks