# Calculating Target Destination

I’m having a bit of trouble figuring this one out. What I’m trying to achieve is a sort of tackling motion. The player lunges at the target from a distance.

The diagram shows the set up. The blue diamond is the player and the red thing is the target. The purple box is the renderer bounds of the targets SkinnedMeshRenderer. I’m using renderer bounds because some target’s mesh are much larger than other. Currently, the player is shooting to the orange star…which is unrealistic. I want him to, no matter what way the target is facing, always target the closest point of the target relative to his position…in the diagram’s case that would be the brown star. Here’s the code I’ve been using…

``````    public IEnumerator Blitz()
{
rigidbody.velocity = Vector3.zero; //ZERO OUT THE RIGIDBODY VELOCITY TO GET READY FOR THE BLITZ
SkinnedMeshRenderer image = target.GetComponentInChildren<SkinnedMeshRenderer>();
Vector3 position = image.renderer.bounds.center + image.renderer.bounds.extents;
position.y = target.transform.position.y;
while(Vector3.Distance(transform.position, position) > 0.5f)
{
transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * 10);
yield return null;
}
Results(); //IRRELEVANT TO THIS PROBLEM. THIS CALCULATES DAMAGE.
Blitz.Stop(); //THE PARTICLE EFFECT ASSOCIATED WITH THE BLITZ.
GetComponent<Animator>().SetBool(moveName, false); //TRANSITIONS OUT OF THE BLITZ ANIMATION
GetComponent<Input>().NotAttacking(); //LET'S THE INPUT SCRIPT KNOW THE PLAYER CAN HAVE CONTROL BACK.
}
``````

BUMP…

If it was me I would Just calculate the centerpoint ( or however close you want to be to the target ) of the Player and targets transform, then lerp to that position. It might not be as pixel perfect as you’re trying to set it up but might work better. Since it seems that the stop point changes if the hit point is rotated?

How would the “stop point” change though? The “stop point” is determined before the while loop…and never updated after the while loop gets started. Shouldn’t the “stop point” remain the same even if the hit point is rotated?

To address your suggestion…can you suggestion a way to determine how close I want to be to the target based on the target’s renderer.bounds and the player’s renderer.bounds?