- Home /
Question by
erichewston · Dec 20, 2019 at 08:00 AM ·
rotationinstantiateobjectvelocity
how do I keep each cloned object at a certain point after trigger
Hi, I'm recreating a knife throwing game like knife hit and what I have encountered is when I press a key to instantiate my knife object :
-the first knife when it hits the log collider is perfect as it will stop and rotate with the log -when I start to instantiate the next knife object(s) my original knife will move off and will start rotating as will the other ones I duplicate
here is my log script :
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class LogScript : MonoBehaviour {
public float rotateSpeed = 3f;
public GameObject knifePrefab;
void FixedUpdate () {
RotateLog();
}
void RotateLog()
{
transform.Rotate(0,0, rotateSpeed);
}
private void OnTriggerEnter2D(Collider2D target)
{
if (target.tag == "Player")
{
target.GetComponent<Rigidbody2D>().velocity = new Vector2(0,0);
target.transform.parent = this.transform;
Instantiate(knifePrefab, new Vector2(0, -3.5f), Quaternion.identity);
}
}
}// end class
thanks in advance. Eric
Comment