If collided have ObjectA follow ontop of ObjectB
I'm trying to make it where when a player collides with a bubble it will stay on the object it collided with, the catch is that there are multiple objects that the player play as, here's part of the code I've been messing around with for the past couple of days. It will only jump to 27 units on the x-axis from the original position.
Because once the timer runs out the bubble pops and returns to home location. (Which does work currently)
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player") {
attached = true;
transform.position.x = other.transform.position.x;
transform.position.y = other.transform.position.y;
transform.position.z = other.transform.position.z;
}
}
Answer by vintar · Jan 16, 2016 at 12:27 PM
You could just set the player as a child of the bubble it collides with, and unchild it when the bubble pops. Like :
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "Player")
{
attached = true;
transform.SetParent(other.transform);
}
}
then when the bubble pops :
transform.parent = null;
If I pause the game and zero out the position it will go to where it needs to be. How would I make the code itself do that? @vintar
I added this to make it stay on the player after the testing if the other object is the player.
transform.localPosition = new Vector3(0, 0, 0);
Answer by MidnightDragonT · Jan 17, 2016 at 10:51 AM
Sadly that didn't help it makes the bubble go off screen, I believe on the z axis.
Your answer
Follow this Question
Related Questions
Trigger detects player collision and play specific audio from array 1 Answer
Need to know why this script only works sometimes? 1 Answer
Unexisting blocks colliding and existing block not colliding 1 Answer
How to make the enemy kill a specific player instance?,How do I kill a specific Player instance? 0 Answers
My player invisble to other players but i can still see other players 1 Answer