- Home /
How do you make the waypoint system work for objects instantiated?
I am attempting to make a mario kart game in unity and I am at the part of making red shells. My idea was to make the red shell follow a waypoint system until it locks on a target. I tested it with a red shell that is in the scene before I play the game, and that follows the waypoints as expected. When I instantiate a red shell however anywhere on the track, the shell starts freaking out and moves and shakes in random directions. I even made the player track which waypoint the player is on currently, so when I spawn the shell, the shell goes to the next one from the player. Nothing fixes this problem. Does anyone have a solution, thanks.
Answer by toishaanpatel · May 11, 2020 at 04:23 PM
Nevermind, the shell had a wrong reference, and now everything is fixed.
Answer by Tario · May 10, 2020 at 07:40 PM
How does the shell decide it's reached the next checkpoint? I used to have problems where agents would be moving too fast, overshoot their destination and then turn around and overshoot it again, causing them to flip back and forth on the spot.
The solution was to say that they'd reached their destination once they'd gotten within x many units of it.
I add box colliders to each waypoint which has a width that spans the track width. It is set to IsTrigger. So the shell still goes to the transform of that empty object which is the center of the object , but I also added a ontriggerenter to add 1 to the currentwaypoint index, so even if the shell did not technically make it exactly to the current waypoint, by entering its collider, it would have.
I do the ontrigger by checking if this trigger that the shell entered is the same gameobject as the next element in the waypoint array The reason I did not do the x units thing u were talking aboit is because that would in theory add a pretend sphere collider to it as it would be x units on all directions of the waypoint. I only want it to be x units perpendicular to the track's direction, so box colliders work well