I am currently working on adding a trail of game objects to my player who can be launched; they are animated sprites. I know I could use a particle system or something else like that - but for this project we have decided it must be game objects since it is all hand animated for the overall effect that we are going for.
So basically, I track the players velocity. If it hits a certain threshold I instantiate trail objects. The PROBLEM is if I travel a shorter distance - the spacing between objects is perfect… if I travel a longer distance I end up with large gaps in between my game objects. I am trying to have the spacing look the same regardless of the distance traveled.
If you are traveling at a greater speed then the distance traveled between each update is naturally going to be greater. So instead of spawning an object each time, record the position each update. then spawn objects in between the last position and the new position based on your separation.
Something like this(its a hack)
Vector3 lastUpdate;
float delta = 10;
void Update()
{
var pos = transform.position;
if (Vector3.Distance(lastUpdate, pos) > delta)
{
// Spawn points between
lastUpdate = pos;
}
}
Okay awesome! I was trying something similar earlier, tracking the player then seeing if the player had moved the equal distance of the size of the game object sprites - but was not able to get it to run properly! I will try this now! Thank you very much!
EDIT: It was my delta, I set it to 1 now it looks good! Still during launch I am getting gaps though. But might just need some fine tuning.
EDIT #2: Okay so it works great if I am just moving around - like perfectly! However I am more interested in during a launch. Which uses addforce. I get gaps when I launch from one corner to the opposite corner. Do you have any suggestions for that?
You need to calculate the spawn position.
E.G Take the last place you spawned and use MoveTowards the next point. Keep calling it till you have closed the gap.
Excellent! With some very minor adjustments this is working perfectly for the application! I basically just added clearing of lastSpawnPoint to vector3.zero once the loop had completed, otherwise I was getting some strange results! Thank you very much!!