How would I spawn the game object AS a child of the player? Rather than attach it after its birth. That way, I can use localPosition as the position, and the radius will be drawn around the player instead of the origin of the world.
Thing is the name of the function doesn’t help too much to find it.
Would be ask too much if someone helps to write a code that makes this new instantiated object not to just appear on that random position, but instead moving there with a decreasing speed and possibly and arc or bezier path?
In my case, I am generating coins drop, and that fluid movement would give a nice visual touch.
I got some ideas on my own that consists, passing the target position to the new instantiated object (coin) and the coin would handle the moviment.
To to that movement, the distance travelled per each frame would use some king of lerp. But the position calculated each frame resulting in an arc, would be the hardest, i think.
I’m glad to see that my advice is still helping people, even years later
Can’t spare the time, but you appear to have a pretty good idea already of what you want to do - for now get it working with simple Vector3.Lerp. Once that’s done, take a look around for some tweening libraries.
I think your advice on break up the feature on two step task is the way to go, but as in an early stage project I feel that moving other things on is more crucial, and visual effects could be added later in this case.
If things work out later, I can post some results here.
Well, I got the solution for my problem. Partially at least.
I made the fist part, slowly movementing the objet to it’s target position using Vector3.Lerp.
The final result is really satisfying, and I think I will not need the arc movement feature. It will not add too much as visual effect as the camera is far from the events. But I think it would increase algorithm complexity, and would cut the performance down as the idea is instantiate lots of gameobjects with this behaviour.
I have one final question though.
How is the most adequate way to check if the object reached its final Vector3 position?
The way I came up was:
// Update is called once per frame
void Update () {
transform.Rotate(Vector3.up * spinSpeed * Time.deltaTime, Space.Self);
if (!reachedPosition)
{
transform.position = Vector3.Lerp(transform.position, targetPos, movementSpeed * Time.deltaTime);
//THIS is where my doubt exists.
if (Vector3.Distance(transform.position, targetPos) <= minDistance)
{
reachedPosition = true;
}
}
}
I`m not concerned with pinpoint precision of the positioning, but with performance instead.