12
\$\begingroup\$

I've got this character in Unity3D (2D Mode)... in a a slope which looks like this, enter image description here

But I want the character to stand along the red line..Like below enter image description here

How can I make it in Unity3d?

I've got this setup..

enter image description here

I'm using simple Addforce for movement... If I remove the z position constraint it results in weird movement like rolling and so on.... Any help would be appreciated :)

\$\endgroup\$
28
\$\begingroup\$

Have you considered that it looks very odd for a person to standing perpendicular to a slope?

standing perpendicular to a slope

You need to be upright to stay in balance.


Some alternatives:

  • Treat his feet as a separate object and rotate them to be parallel to the slope. (A raycast will find the angle's normal, as dnk described. The angle for the feet is that + 90°.)

    rotated feet

  • Fake it, by moving the whole character a little downwards.

    faked "rotated" feet

\$\endgroup\$
  • 3
    \$\begingroup\$ thank you all :) I made this after your suggestion i.imgur.com/io3v7Y4.png \$\endgroup\$ – jamius19 Sep 5 '15 at 19:31
  • 1
    \$\begingroup\$ That also suggests that as soon as the rotated feet do not look nicely any more, your character should stumble :) \$\endgroup\$ – Hagen von Eitzen Sep 6 '15 at 7:16
  • \$\begingroup\$ :-/ Does the rotation of the feet look odd in the picture I attached? \$\endgroup\$ – jamius19 Sep 6 '15 at 9:49
  • \$\begingroup\$ @jamius19 They look good to me. I think Hagen's comment was a joke. \$\endgroup\$ – Anko Sep 6 '15 at 11:32
  • 1
    \$\begingroup\$ You don't need to move the character downwards just move the visual of the slope upwards a bit relative to the physical \$\endgroup\$ – ratchet freak Sep 6 '15 at 14:19
2
\$\begingroup\$

Try using RaycastHit.normal on ground to get normal. Them put char.up = normal

\$\endgroup\$
  • 1
    \$\begingroup\$ Why waste CPU with a raycast if the Unity physics already gives this information by default on every collision? \$\endgroup\$ – Kroltan Sep 5 '15 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.