- Home /
Movement on a tube
I'm working on a game similar to Sonic Lost World, and I need to get the movement on a tube-like level like in that. I've tried turning off physics and seeing the gravity to always be downwards relative to the player, and unfortunately that didn't work. The closest thing I can find to this problem is moving on a sphere like in Mario Galaxy, which doesn't work at all with the tube-like level because the player will just gravitate towards the level's pivot point instead of keeping the mesh upright at any angle.
Answer by sparkzbarca · Aug 09, 2015 at 02:56 AM
raycast down. get the terrains normal, use the terrains normal (which will be your up) + the characters transform.right in a vector.cross(..) to get the new transform.lookat(...) That will allow you to always be "level" on the ground.
for a brief PSEUDO code example
UPDATED
Vector3 Right = transform.right;
RaycastHit Hit;
Physics.Raycast(transform.position,-transform.up, out Hit)
Vector3 Up = Hit.normal;
Vector3 Forward = Vector3.Cross(Right,Up);
Vector3 LookPos = transform.position + Forward;
Void Update()
{
transform.Lookat(LookPos);
}
Message if you need any help understanding or coding.
It's giving me issues with Up because hit isn't a bool.
I can't copy and paste anything because I don't have any internet on my computer and am posting from my phone.
$$anonymous$$ore specifically, it says "Type 'bool' does not contain a definition for 'hit' and no extension method 'hit' of type 'bool' could be found."
yea i already changed it, though again thats pseudo code but yea see the new code. there is not .hit. just straight to .normal.
oh whoops noticed another thign im goign to update the code again in a $$anonymous$$ute :P you'll ahve to pass the raycast out to a hit variable I forgot that unique part of raycast whoops. :P
It still says 'System.Boolean' does not contain a definition for 'normal'
updated now, forgot raycast returns a bool not the hitinfo and you have to send in a variable its stored in, its updated now.