Object Follow Path
Blitz3D Forums/Blitz3D Programming/Object Follow Path
| ||
What would be the best way to code an object (white box in picture ) to follow a path. The path has curves and straight lines. please take a look at the picture thankyou |
| ||
A simple waypoint system will do this. Place waypoints at each each point on the line where the direction changes. Use more to define the curve. For the white cube, hold a current and target waypoint. Get the direction of movement from the current waypoint to the target and move the square in this direction. Once within a certain distance of the target waypoint, snap to that point and change the current to the target and increment the target etc.. etc.. There's obviously a wee bit more work to it but I don't have time to knock up any code I'm afraid. Stevie |
| ||
have a look at 'splines' or 'bezier curves' if you want super-smoothe movement on curved sections |
| ||
splines or bezier curves seem to much maths and calculations for me. something simple please. |
| ||
it's pretty simple. store X minus nextwaypointX and Z minus nextwaypointZ. Then move your mesh one step towards the next waypoint (you may use a dummy pivot to use PointEntity). Now get X minus nextwaypointX and Z minus nextwaypointZ again. if the old and the new values are not both positive or both negative (on X or on Z), then the mesh has passed the waypoint, you may then increase the next-waypoint counter. Of course this also works not only with XZ, but also with XYZ dimensions. |