Question by
Tom_OBrien · Oct 31, 2021 at 01:36 AM ·
transform2d gametransform.positionnewbie
Need 2D help - Want to have object move towards point when it touches a trigger.
Initially, the object is sent straight downwards from a point at a random speed.
if (vinePlacement == 1)
{
transform.position = new Vector2(-5.86f, 5.93f);
rb.AddForce(new Vector3(0, (Random.Range(-50, -150))));
}
Once the object reaches a certain point, When it comes in contact with a 'Jump' Trigger, it is meant to stop traveling downwards and then start moving towards a point, indicated by the 'target'. However everything I have tried for this has not worked.
public Transform target;
public float speed = 1;
void OnTriggerEnter2D(Collider2D coll)
{
if (coll.gameObject.tag == "Jump")
{
Debug.Log("Touched");
transform.position = Vector3.MoveTowards(transform.position, target.position, speed * Time.deltaTime);
}
Can anyone give me a hand as to what I am doing wrong here? Much appreciated in advance!
Comment