Hello,
hopefully this makes sense…
what I have going right now, is a NPC running away from the player, but technically using the MoveTowards function:
transform.position = Vector2.MoveTowards(transform.position, target.position, -moveSpeed * Time.deltaTime);
the Target is the player, Transform is of course the object/NPC, however I want it to run further than the target, which I have it running backwards the way i want -moveSpeed float variable, however it will just run for a certain amount of distance… I do have a “Circle” that checks if overlaping:
runAwaySafe = Physics2D.OverlapCircle(transform.position, checkrunAwaySafeRadius, WhatIsPlayer);
however I want it to be able to reach it, and then… or else… so I am trying to figure that part out…
hopefull this makes sense… if not maybe picture below may help?
NPC is the blue, black is the player, if player goes inside the OverLapCircle, then NPC runs till it gets to the Green Safe or the runAwaySafe… again I have the overlap circle:
transform.position = Vector2.MoveTowards(transform.position, target.position, -moveSpeed * Time.deltaTime);
but not sure what I should put… I tried this:
if (runAwaySafe)
{
Vector2 dir = target.position - transform.position;
transform.position = Vector2.MoveTowards(transform.position, target.position, -moveSpeed * Time.deltaTime);
Quaternion toRotate = Quaternion.LookRotation(Vector3.forward, -dir);
transform.rotation = Quaternion.Lerp(transform.rotation, toRotate, RunSpeed);
}
BUT… runs away… but something maybe the target.position i need to add or maybe something else? maybe change it entirely?? not sure, any thoughts?