Hi all.
I am using the below to throw the Boomerang. It works well if you look at the gif.
What I can’t figure out is on this part. The Boomerang flies to the target max Distance. I want it to slow down Just before it start returning and pick up speed back to the player.
Any help would be great. Thanks!
rb.velocity = transform.up * speed; // Calculate to go slower when close
Or Better stated. Slow down before reaching Max distance
void Update()
{
//Makes the boomerang rotate around its pivot
spriteHolder.transform.Rotate(0f, 0f, rotationSpeed * Time.deltaTime);
//Checks if the distance between the spawn point and the boomerang is greater than the maximum distance
//If it is true and IsTrown is true, the boomerang will return to the player
//Get Max Distance from SpawnPoint. If reached return to player
if (Vector2.Distance(transform.position, spawn) >= MaxDistance && IsThrown)
{
CanReturn = true;
}
if (CanReturn)
{
GoBack();
}
}
public void Throw(Transform spawnPoint) //called from player when Spawning Boom
{
if (!IsThrown)
{
//Makes the boomerang move
rb.velocity = transform.up * speed; // Calculate to go slower when close
//Contains the spawn point
spawn = spawnPoint.position;
IsThrown = true;
}
else
{
return;
}
}
void GoBack()
{
CanReturn = true;
//Calculates the direction so it can return to the player
Vector2 playerPos = player.position - transform.position;
rb.velocity = playerPos.normalized * speed;
//Checks if the distances between player and the boomerang is less than the GrabDistance
//If it is true it will be destroy the boomerang
if (Vector2.Distance(transform.position, player.position) < GrabDistance)
{
//Allows the player to throw another boomerang
// GameObject.FindGameObjectWithTag("Player").GetComponent<AttachToPlayer>().CanThrowBoomerang = true;
GameObject.FindGameObjectWithTag("Player").GetComponent<Aiming>().CanThrowBoomerang = true;
Destroy(gameObject);
}
}
