Context: infinite runner, stationary player, obstacles move toward player. I have an asteroid that currently Vector3.MoveTowards a moving target e.g. a "rubble" object spawns hidden far away from player and moves toward player. At time of spawn, an asteroid spawns well above it and starts moving toward the rubble. When they collide, rubble appears, asteroid disappears, boom, particles, etc.
TL;DR
I want a kinematic object to track high for awhile and dive bomb at the last minute to crash into a moving target with variable speed (final location unknown.) I also want animation curves to tweak the speed and dive bomb effects.
The meat
The goal: I'd like the asteroid to track mostly high until some time close to impact and then sort of dive bomb down toward the rubble. I want to control the speed with an animation curve in the inspector. Bonus points if I can control the "dive bomb" intensity with another animation curve. I'd like to keep the motion smooth (I thought of maybe trying to calculate
The problem: The current path of motion is lame. The asteroid just gradually moves down and sort of asymptotically (to the ground) hits the rubble since I'm just using Vector3.MoveTowards with a moving target. Even if I try to control its speed over time, it's not what I'm looking for. The game speed also changes variably, so it would be tricky at best to figure out the actual final destination of the target.
How can I keep the asteroid high-ish until a point, then start dive bombing for a more dramatic crash? I'm thinking somehow the distance and/or time need to be normalized to use the animation curve, but I don't know how to do it when the target moves variably. I've attempted to normalize it, but maybe just can't get the math right. Can time spent traveling be normalized if you don't know how long it will travel?
The current lame code:
timeSinceStart += Time.deltaTime; float baseSpeed = GameManager.gm.speed * gameSpeedMultiplier; float adjustedSpeed = baseSpeed * speedCurve.Evaluate(timeSinceStart); float step = adjustedSpeed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, target.transform.position, step); transform.Rotate(randomRotation, rotationSpeed * Time.deltaTime); Update: sketched image
- A == asteroid
- R == rubble/target
- P == player
