- Home /
How to rotate Character depending on the inclination of the platform or its parts?
Hi! I make a Sonic game in Unity. This game requires 360 degrees character movement, because it has different platforms, including "Loops". How to make this movement? Thanks.
Answer by matyicsapo · Jun 24, 2010 at 07:45 AM
Raycasting from you char towards it's bottom (that is not down on the global Y axis) it'll hit the ground beneath it's feet and you'll get a RaycastHit which contains the hit ground's normal from which you can calculate the dir which goes along this surface using Vector3.OrthoNormaliz() which is the dir you should be able to move on the surface.
I'm not that smart but in 2D I'd do the actual rotation by finding the angle between the char's forward vector and the newly hit surface's paralell dir (the move dir I mean which you calced already) and rotate the char by it's forward axis by this angle.
Hope this gets you started :)
Sry if it wasn't too clear and another for my could-be-better-english and another if I said sg. totally non-sense.
Yes! It works, but Sonic doesn't rotate in the "Loops" 360 degrees. He can only move to its wall.
is gravity applied, isn't that what's stopping him from going up the ceiling? or if the inclination of the surface is too abrupt that could be a problem too(no other ideas atm - it's very early here)
Oh, no! I doesn't help. $$anonymous$$aybe, I need to create some kind of... waypoint...
Could you check my code? $$anonymous$$aybe, I did something wrong... http://depositfiles.com/files/6gm3f5ese
checked it but I couldn't find anything that striking sry...you could narrow the problem down it's root by debuging with a bunch of logs and watches for could-be-problematic stuff...really wish I could help more but it seems I still have a lot to learn too :D