My game is a 3D game.
Earlier, I had a basic repair script attached to a gameobject. Whenever I swing my repair hammer, it turns on it’s collider and if it something with the tag “repairable” it would then do a “theCollider.transform.SendMessage (“ApplyHeal”, TheRepair, SendMessageOptions.DontRequireReceiver);”
I then noticed that my other onTrigger functions are doing the same, such as an arrow or bullet doesn’t collide with the wall when it hits, unless I’m very far away. If I get to close, it just passes through the object like it doesn’t exist.
It seems to have started since my last Unity update, but I doubt that it the cause.
Would anyone be able to point me in the right direction on what is going on?
I apologize for the vagueness, but I can’t really pinpoint what the problem is, aside from the On Trigger is working much slower if at all.
I tried changing the fixedTimeStep and such, but it doesn’t seem to help.
i’ve experienced similar issues with triggers and colliders sometimes to fix these u can change the rigidbodys collision detection to continuous, if this doesn’t help you maybe you change some of your system to be a raycast, as for your trigger delay i can’t be sure of the cause but if i were to speculate i would have to wonder how much information your script processes before doing something with the trigger i’ll provide a couple of my own methods for using triggers to define an object for interaction and also a simple raycast that i use to loot items which should be easy to adapt for alot of cases such as shooting bullets.
this is my method for assigning an interactable object. u can place this on any object that has a trigger.
void OnTriggerEnter(Collider Other){
if (Other.gameObject.tag == "Player") {
PlayerInteraction pit = Other.GetComponent<PlayerInteraction>();
if(pit.interTarg == null) {
pit.interTarg = gameObject;
}
if(pit.interTarg != null) {
pit.nextTarg = gameObject;
}
}
}
void OnTriggerExit(Collider Other){
if (Other.gameObject.tag == "Player") {
PlayerInteraction pit = Other.GetComponent<PlayerInteraction>();
if(pit.interTarg == gameObject && pit.nextTarg != null) {
pit.interTarg = pit.nextTarg;
pit.nextTarg = null;
}
if(pit.interTarg == gameObject && pit.nextTarg == null) {
pit.interTarg = null;
}
}
}
}
// a brief breakdown of how it works this assumes that the Player has a script called PlayerInteraction upon this PlayerInteraction script there is 2 GameObject Variables one named interTarg, which is the current target for interaction. and nextTarg ,this is for if we manage to stand on 2 triggers simaltanously.
and note that you will never need to make changes to the above
since u will be doing everything with these Interactions within your PlayerInteraction a simple example to be used in playerinteraction below.
// first checking if we have a target of interaction.
if(interTarg != null) {
// this is where would check information regarding the target
// before we do something to it
if(interTarg.tag == "Shop") {
showShopGUI = true;
}
}
// then i would go on to use that bool for some GUI display.
// Forward Raycast from our cam, hit represent the impact point of the ray
// i use it below to see if we hit a transform then check the name of that transform
// before accepting an input key to pick the item up
RaycastHit hit = new RaycastHit ();
/// uncomment below to see the raycast in the scene.
//Debug.DrawRay (GetComponentInChildren<Camera>().transform.position, GetComponentInChildren<Camera>().transform.forward * 3f, Color.blue, 1f);
Physics.Raycast (GetComponentInChildren<Camera>().transform.position, GetComponentInChildren<Camera>().transform.forward * 3f, out hit, 15f);
if(hit.transform != null && hit.transform.tag == "Loot") {
if(Input.GetKeyDown(Keycode.E)) {
LootItem(hit.transform);
}
}
// if i was unclear on anything or u need help understanding something i didn’t cover feel free to email me Skylem@live.com.au
appologies for the long winded answer, i did my best to only include information relevant to a possible solution
I finally found out what was causing it.
It was REALLY weird, but for some reason my physics manager had it that anything on my draw layer (in this case my arms and hammer) couldn’t hit anything layer Default (the repairable objects)
But good news is I got it fixed!
Still no idea how that happened. I haven’t touch the physics manager in months… 0_o