getSurfaceNormal and setHpr

I have a camera that is reparentTo a cube, so i can drive it whith a collision onto the ground.
Now i’d like my camera to be Pitched acording to the ground’s normal, so my code is :

if (len(entries)>0) and (entries[0].getIntoNode().getName() == "mapwiimotetoile2"): 
	normal = entries[0].getSurfaceNormal(base.camdad)
    if normal[0] > 1 or -normal[0] < -1 :
        camAcc = normal[0]/5
    else : 
        camAcc = 0 
	base.camdad.setP(base.camdad, camAcc)

, where base.camdad is the father of my camera.

But result of this looks crazy, and i can’t really understand what it does (:oops:) .
I must say i don’t know mutch about normals and their values …
I didn’t found doc or sample about this but i’m sure that someone have ever write such a code.

Thanks in advance

Ok, i should have setP on the cam itself, and in a global mode, and not on it’s father with a local mode :


It looks like it’s working, but it’s giving a very hard movement because of the model’s definition.

Is there a way to soft this ?
Do anyone have a sample of orientating an object using a model’s normal ?


HPR is for rotation which shouldn’t be confused with the normal vector.
Use lookAt instead. e.g.

obj.lookAt(render, Point3(obj.getPos(render) + normal))


I’ve tried this, but i need to set only the pitch of my cam, yaw is drive by something else.

So i put a dumy to lookAt, and than copy it’s P to the cam.

Result looks the same when i used base.camList[0].setP(normal[0]*3).

Thanks again