- Home /
Magnetic Race Track? How to stick to a tubular track?
So in F-Zero which is what my game is based on, you go around these 'tubular' race tracks, like this: https://www.youtube.com/watch?v=9k6kvFg5Ih8#t=53 (0:53)
You can freely race around the cylinder, whether it be from the top, sides, or bottom and you totally stick to it like a magnet. Of course it's hovercars that hover slightly above the track, but still.
I've tried to recreate that with the cylinder GameObject in Unity, and scripts.
Most scripts I've tried were seen in this thread: http://forum.unity3d.com/threads/how-in-the-world-were-the-physics-in-f-zero-x-done.204747/
I've also browsed unity answers forever, this has been getting me for days since I need to figure out a reliable way that works with any type of gameobject, any type of car and isn't buggy as heck. I've even tried to combine various scripts.
Do keep in $$anonymous$$d that these games do not actually utilize physics either on the sole axis or in its entirety when in contact with the track, but rather simulate it. The unity analog is that the tracks have a series of rotated box-collider entities upon which' touching disables physics/gravity/whatever on the relevant plane, and forces the object to keep it locked within distance from the closest, possibly raycasted collision box it can find.
There are more advanced ways of doing this, but this is probably the easiest way, if not the cheapest.
There's also the "raycast collider" in unity, try experimenting with that.
How about adding a force to the transform.up while you are ridding the tube? Obviously not the best solution but might work and its simple enough. Lets us know if you do manage to achieve this, cause its cool :D
You can make it so the map turns ins$$anonymous$$d of the character
@Sethhalocat : how would you do that exacly? can you be more specific, sounds interesting
@Sethhalocat I eventually plan on making this game at least 4 players online, maybe more, so that's definitely not happening.
Answer by tswalk · Feb 24, 2015 at 04:22 AM
if you were dead-set on using physics,...
i would test:
turning gravity off on objects and relying only on forces (like being in space.. zero 'g').
apply a directional force from the bottom of the 'hover craft' toward the surface normal of the track (tube)
use a 'forward' force on the hover craft to propel the object in that direction
you may also look at using physics joints between the hover craft and an empty gameobject that sticks to the surface of the track.. so if players are hit hard enough, it breaks and they go careening off ... just some thoughts, but I think this could be done with physics alone.
like you said, like a magnet.. gravitational forces are weaker compared to magnetic... so turn them off, and just use the idea of forces to control stuff.
surface normal...? also how would i get it to rotate around, thats the main thing im looking for is rotate around if you drive slightly down the track ins$$anonymous$$d of completely forward.
one simple example is using colliders:
void OnCollisionEnter(Collision collision)
{
foreach (ContactPoint contact in collision.contacts)
{
Debug.DrawRay(contact.point, contact.normal, Color.red,50);
}
}
... have a box collider below the ship and use a static collider (based on mesh of the tube) for the track. You may be able to pull the contact.normal vector and use this to apply a "force" on the rigidbody of the ship.
you can apply a constant force or other types to the player based on the controller movement.