- Home /
How to clone on collision
Hello! I know this is a duplicate but I do not understand. Is there any way to periodically clone, (Like every 5 seconds) on collision? I tried scripts kindly provided by the people who answer here, but the scripts spawn away from the player. Eg: Player is at Z 560 but the spawn is at Z 1, I also tried multiple follow scripts including:`
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.position = player.position + offset;
}
}
But it does not follow and instead causes bugs, any ideas? Here the code I got so far
void Start()
{
FindObjectOfType<Moveafter>().enabled = false;
FindObjectOfType<clonefor4>().enabled = false;
}
// Update is called once per frame
void Update()
{
}
IEnumerator OnCollisionEnter(Collision collisionInfo)
{
if (collisionInfo.collider.name == "Activateblock1")
{
FindObjectOfType<Moveafter>().enabled = true;
FindObjectOfType<clonething>().enabled = true;//clone script
FindObjectOfType<finalmoveplayer>().enabled = false;
yield return new WaitForSeconds(50);
FindObjectOfType<finalmoveplayer>().enabled = true;
FindObjectOfType<Moveafter>().enabled = false;
FindObjectOfType<clonething>().enabled = false;
}
}
} ` Thanks!
Did you add a Debug.Log(player.position) in that Update before you set the position to check if it is what you expect? What is the value of offset? Also, if you just want the object to have an offset from the player, you can parent it to the player object with a local position equal to the offset.
Thanks for replying! Yes, I tried everything you mentioned. For future reference, the parent does not work because my rigidbody is kinematic. Sorry if I worded it wrong, I meant if the player was somewhere, the clone will clone with an offset of the player. In simpler terms, if I want the clone to clone in plane 7, it will clone in the object with the cloning script and not clone in plane 1. Sorry again, I hope you understand what I mean now. Thanks!
Are you sure your FindObjectOfType is finding the right one? If the script is on the collided one, you should do collisionInfo.collider.GetComponent ins$$anonymous$$d
Ok, thanks! But do you know how to clone on a single game object? Thanks for helping out.
I am ending this post a creating a new one, thanks to you I simplified my problem. Thanks for replying!
Your answer
Follow this Question
Related Questions
How to clone with a object. 3 Answers
Cloning a game object. 1 Answer
Player not following touch after camera is rotated? 0 Answers
Make Object Move to/follow Another Object? (plus turn towards it) 3 Answers