Model Rotation on Terrain

Using the Roaming-Ralph tutorial, I’m curious how I would make the character’s model rotate along the terrain?

I’m aiming for something like this. I’d also like to manage the speed along the slopes, but I’m not sure how I would do that. I’m fairly new with Python, but I’m pretty good at C++

Thanks :slight_smile:

Tricky. If you create a terrain in a modeler, make sure you have normals generated somehow. (Maybe the egg loader already does this, I don’t know.)
In your code, you would need to adjust ralph/sonic’s rotation based on the normal (something like self.ralph.lookAt(self.ralph.getPos()+entry.getSurfaceNormal()), but if you do that you need to make sure you rotate the collision ray as well.

HTH.

Thanks pro-rsoft,
My biggest problem is figuring out how I would rotate the collision ray at this point. For some reason I don’t see it as being very plausible…

-Nate

I assume don’t want your characters to be able to climb a vertical wall this way. Just “smooth” changes in surface normal, like the ramp/loop on the picture.

So you could start out with your current character down vector each frame, raycast for a (ground) contact point, get the ground normal, and then adjust your character rotation to make the ground normal your new character down direction. But only if the difference in direction between ground normal and old down direction is not too big --> dot product. From there on you could use “normal” character movement code. Might be you have to do a second raycast for this part.

enn0x

How about casting a collision ray (from a point above the previous collision point, aka body) to the point you are moving to, get the collision normal as described above. Move to the collision point, and repeat the steps.

  |:->*      <- character
   \ /  <- colliision ray, gets next normal
     \ 
     ground

  |    ,*
   \ ./ | <- moved to collision point, normal -> rotation
     \' |  <- new collision ray
       \|
         \
    ground

i hope the illistration helps :slight_smile:

I just dont know how to rotate the character to match the normal…

why not use an collision sphere?, get the collision point and do an “LookAt” like operation on the model with the collisin point…

Thanks everyone :slight_smile:

enn0x - But there’s problems with that… I’d have to do that for each action, running, idle, etc… He’d look okay running (if I spent many hours perfecting the rotation) but the moment he stood up, he’d be standing on uneven terrain. If he walked sideways on terrain, he’d be angled forward as he should be walking on it head-on- or maybe I’m not thinking about this right.

ThomasEgi - That would make sense… how would I go about coding that?

Spheres can be tricky because they can have more than one contact point. For example when bumping into a wall or when encountering a slope. Which one to choose?

The rotation itself won’t be expensive, in terms of coding time - lookAt will do everything, like ThomasEgi pointed out. But first one contact point has to be found.