Question by
j-washington2 · Dec 06, 2020 at 07:52 AM ·
rigidbodylerp
How to move a rigidbody toward a position that is constantly moving, while the rigidbody is also a child of the moving target's parent?
I have a character that is trying move away from an enemy, however, I want the enemy to stay within a certain distance to the player and move at or around the same speed as the player so I made the enemy a child of the player and it is supposed to lerp from the farthest point which is just beyond the camera's view towards the attack point on the character. Those are both different empty gameobjects that are also children of the player. When the enemy is activated it stays at the farthest point though. Where am I going wrong, or what should I be doing differently? This function is being called in Update().
if (chasing)
{
dogRb.transform.LookAt(player.transform);
dogRb.MovePosition(new Vector3(Mathf.Lerp(startPos.position.x, attackPos.position.x, speed / 2), transform.position.y, Mathf.Lerp(startPos.position.z, attackPos.position.z, speed)));}
Comment