Help with registering collisions while snapping an object in-game
I have a custom made modular building script, that when I place the objects it snaps to the grid. The only problem is that when the object snaps to the grid it bypasses the part of my script that checks to see if there's an object where I want to build
function OnCollisionEnter()
{
triggerEntered = true;
GetComponent.<Renderer>().material = redMaterial;
}
function OnCollisionExit()
{
triggerEntered = false;
GetComponent.<Renderer>().material = greenMaterial;
}
the snap system is this
if(Physics.Raycast (ray, hit, 6))
{
Debug.DrawLine (ray.origin, hit.point);
heldFloor.transform.position = Vector3(Mathf.Round(hit.point.x),Mathf.Round(hit.point.y),Mathf.Round(hit.point.z));
}
Thanks in advance
Answer by rageingnonsense · Oct 01, 2015 at 10:01 PM
if(Physics.Raycast (ray, hit, 6) && !triggerEntered)
{
Debug.DrawLine (ray.origin, hit.point);
heldFloor.transform.position = Vector3(Mathf.Round(hit.point.x),Mathf.Round(hit.point.y),Mathf.Round(hit.point.z));
}
Have you tried that?
I gave that a try and it didn't work. I think that the problem is that the object is not registering a collision enter because I'm transfor$$anonymous$$g it to different positions ins$$anonymous$$d of dragging it over. So it never enters it's just all of a sudden there.
p.s The material doesn't even change when I put it over an object and I do have a box collider on the box set to trigger.
Answer by $$anonymous$$ · Oct 02, 2015 at 02:27 AM
Ok I think I found my answer I need to put the object to a rigidbody.
P.s if any body wants the script I'll be more then happy to share it.
Your answer
Follow this Question
Related Questions
How can i restart a script on collision ? 1 Answer
Evil Genius Building functions 0 Answers
Make camera collide 2 Answers
Spawn Hazard, clone behave diffrent 0 Answers
How can I pre-generate a grid instead of generating it on each runtime? 1 Answer