Hi all, how can i do to throw a weapon and return again to the player position? like a boomerang. its for a 2D game.
Thanks all.
I dont have the exact code on me, but I have made a boomerang for a topdown game before.
You need to have an object with a rigidbody2d and some type of boomerang script on it. You then need to add a timer variable on that script and count down from how long you want it to take. when the time is reached you find the player and set the velocity equal to the displacement, when the boomerang is within a certain range of the player destroy it.
float timer;
public float forwardTime = 1.0f;
public void Update(){
timer += time.deltaTime;
if(timer >= forwardTime)
getComponent().velocity = findObjectOfType().transform.position - transform.position;
}
}
This is only a bit of the code, you will need to normalize the displacement so its travel rate doesnt change and add a destroy function.