- Home /
gameobject stacking issue
i am trying to make a game that has similar stacknig mechanics with "cube surfers". i created an empty gameobject called it stacks and made it child to player. on my project in theory when player collides with boxes,boxes are supposed to spawn underneath the player. but what happens is video. when player collides, it moves the box under player but inside the ground and the box doesnt push player up so that player can stand on it. when i move the stacks game object next to player instead of underneath it (from (0,-0.5,0) to (1,0,0)) video the stacking is working
please help your brother out with this issue. what shall he do? is putting them as childobject bad idea? if it is what to do ? please guide me thanks
and my code;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
Transform otherTransform = other.transform;
Rigidbody otherRb = otherTransform.GetComponent<Rigidbody>();
otherRb.isKinematic = true;
other.gameObject.GetComponent<BoxCollider>().isTrigger = false;
if (parentPickup == null)
{
parentPickup = otherTransform;
parentPickup.position = stackPosition.position;
parentPickup.parent = stackPosition;
}
else
{
parentPickup.position += Vector3.up * (otherTransform.localScale.y) ;
otherTransform.position = stackPosition.position;
otherTransform.parent = parentPickup;
}
}
}
Hey man, I'm not entirely sure but do you just need to either set the position of the player rigidbody or provide a small impulse force, to raise it up (Player height + number of boxes) above the terrain? Not sure, just an idea :)
i tried it but the boxes follow to impulse aswell with the player
Can you impulse to player then wait for the player height to be the expected height (Player + number of boxes) above terrain then add the box as a child? Otherwise I guess the box becomes a child as the parent is moving up so they move upwards together, which sounds like what you're saying.
Your answer
Follow this Question
Related Questions
Reinitialize prefab 0 Answers
Find one inactive player (gameobject) 2 Answers
Coding Help 0 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers