A hover vehicle that orientates to the ground from multiple points around the vehicle rather than just the centre, so it can smoothly move over terrain and steps and ramps.
So far I have put about 7 points around this tank model. These shoot rays down and position the vehicle above the ground using a desired height number. This means that some points are around 6 studs above the ground while others might only be 4, the idea for this is that there is a gradual increase in height rather than always being at least a certain number of studs above. I would like to use a centre piece to orientate the entire tank based on the positions of the points the rays hit basically. Something similar to this game,
Except not going completely up a wall, but having a maximum angle it can climb like humanoids.
What solutions have you tried so far?
I’ve tried looking on several devforum posts and youtube but it seems most things only orientate from one point from the centre, I’m not sure how I would go about combining several. I have seen a post in which four points combined to orientate a plane between them, but that didn’t actually even work for me when I tested the code. I feel like I understand the concept but not the maths.
My question is basically what sort of solutions can I use to combine multiple points in 3D to orientate a single body gyro for a hovering tank? If anyone has links to any relevant posts or stuff online that would be great as well, thanks for reading.
You should only be using one point because of the information that raycasting provides. RaycastResults tell you the normal vector of the surface that was just hit, allowing you to determine the angle of the ground in your case. Think of the normal vector as an arrow pointing perpendicular from the ground. If you want to use this to rotate a vehicle, you can try creating a new CFrame out of this normal vector and passing it to the BodyGyro’s CFrame. You may have to play with the properties so that it doesn’t rotate your Y-axis.
The concern I have is that if this tank is trying to go up a slope and it’s too large, it won’t be able to because the one point that is being used to orientate it will be too far back even if it’s in the middle and the vehicle will not even begin to start climbing it normally. Or am I wrong in my thinking or what you’re describing?
You can only determine an orientation from some kind of angle or vector. Even if you use multiple, you need to use them to make one orientation. Using four points, you can’t make a perfect plane all the time. Three points will make a triangle that always has a flat plane, but quads are subject to bends. In your case, you could use four points to make two triangles that form a square, then take the average normal vector of the two triangles. The math for getting the normal vector of these triangles is tricky, and I’m not 100% sure how you would pull that off. You just have to pick best method that you can get working.