- Home /
Question by
PhoenixDev_ · Oct 01, 2020 at 06:49 PM ·
2dtriggervector2movetowards
My vector2.movetowards is 2-3x faster when trigger off and trigger on collider collides
I made a code that when the circle collider(trigger on) of the enemy collides with the players box collider enemy starts to move towards player but when i make my box collider's trigger off my enemy gets insane fast. My code look like this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowPlayer : MonoBehaviour
{
private GameObject player;
private GameObject enemy;
void Start()
{
enemy = transform.parent.gameObject;
player = GameObject.Find("Player");
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerStay2D(Collider2D other)
{
if (other.transform.name == "Player")
{
enemy.transform.position = Vector2.MoveTowards(enemy.transform.position, player.transform.position, 4f * Time.deltaTime);
}
}
}
I made a gameobject that in the enemy. And the circle collider is in this gameobject. I dont put circle collider to enemy because enemy already have a collider that do something for another thing ( its trigger is off too.)
Comment
I am having a hard time understanding what you mean. Can you provide screenshots of the colliders and their settings?
i dont know wtf happened but it solved itself