- Home /
Duplicated object doesn't collide but original does
Hi there,
I have an FPS game where you are able to pickup objects (floats in front of the camera until dropped) and carry them around, I also have doors in which the player can't walk through however it seems when a player has picked up an object the object can go through those doors, but however ONLY if that door has been cloned! If I for example build the component again from scratch in the editor the collision works just fine.
Now I'm wondering which of the two are correct, is there a bug in my initial object and the picked up object should go through the door or should the object never go through the door. Below I've explained how things are setup in my scene, thanks for any help you can give.
Edit: Even weirder I have now tried to Instantiate the object while in game instead of dragging in the prefab and that seems to work with the collision.
Edit 2: Okay so only the last instance created seems to work if I place new ones into the scene while it's running the last one created then stops collisions while all the others (even if they previously worked) now stop. There really does seem to be a unity bug behind this.
Player
Rigidbody (on Child Object)
- Mass: 0.2
Gravity: off
Freeze Postions: all on
Free Rotations: all on
Pickupable Object
Rigidbody
- Mass: 0.3
Gravity: on
Door
Rigidbody
- Mass: 1
Gravity: on
Configurable Joint
Axis: 0 1 0
XMotion: Locked
YMotion: Locked
ZMotion: Locked
Angular XMotion: Limited
Angular YMotion: Locked
Angular ZMotion: Locked
Low Angular XLimit: 0
High Angular XLimit: 110
How it happens
Player moves over to pickupable object and hits a button to pick it up
The object is then attached to the rigidbody on the child object of the player via a Spring joint
The player can now move around with the pickedup object in front of the camera
Player now walks up to the door, if the door has been created from scratch the picked up object refuses to go through the door and just gets closer to the player. Otherwise if the door has been duplicated or pulled in as a prefab the player can walk through the door.
Yeah there are definitely colliders to both the picked up object and to the doors, they even send OnCollisionEnter calls they just allow the picked up obejct right through them! However the problem doesn't seem to lie in the prefab itself as the first object I create always works then if I duplicate them or drag it in as a prefab it will then not work.
Answer by opdude · Jan 31, 2013 at 09:09 AM
Okay so I don't really have an answer for this but rather a work around that I have found, which is to recreate the doors while the game is running. This seems to solve the issue for now although I won't be holding my breathe that's for sure! There does seem to be some underlying but in unity that is causing this issue.
I have attached a script that will recreate the object for anyone else who comes up with a similar issue as I did.
using UnityEngine;
public class RecreateSelf : Monobehavious
{
public bool Recreated = false;
void Awake ()
{
if (!Recreated)
{
Recreated = true;
var newObject = Instantiate(gameObject, gameObject.transform.position, gameObject.transform.rotation) as GameObject;
if (newObject != null)
{
newObject.name = gameObject.name;
newObject.transform.parent = gameObject.transform.parent;
}
else
{
Debug.LogError("Unable to re-create instance?");
}
Destroy(gameObject);
}
else
{
Destroy(this);
}
}
}
Your answer
Follow this Question
Related Questions
How do you add a fixed joint to a first person controller 1 Answer
Delayed Collisions Bug continued... 0 Answers
RigidbodyFPSWalker physics problem 0 Answers
Collision Problem with Rigidbody? 1 Answer
Enemy death help 1 Answer