- Home /
How do I stack my objects?
I have objects falling from above. I'm trying to stack. However, if it coincides at a diagonal angle, it is lined up in an undesirable position. I want to line it up exactly. These codes did not work. How should I do it?!
private void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "fall")
{
transform.parent = col.transform;
Vector3 positionobj = transform.position;
positionobj.x = col.transform.position.x;
positionobj.z = col.transform.position.z;
}
}
Answer by iagoccampos · Sep 13, 2020 at 05:01 PM
After define the X and Z positions, you are not assigning back to transform.position.
Vector3 positionobj = transform.position;
positionobj.x = col.transform.position.x;
positionobj.z = col.transform.position.z;
transform.position = positionobj;
Your answer
Follow this Question
Related Questions
Model Teleports after Animation From Spawn to Idle. Collider doesn't follow 0 Answers
Spawning an object on the opposite side of an activator object with no overlaps 1 Answer
physics.OverlapSphere colliders 1 Answer
How to find the direction and distance to move an object so its no longer jammed into another? 0 Answers
How to find the closest point outside a collider from a point inside the collider. 1 Answer