I don't think that is exactly what is needed for an entity that should rotate according to the terrain slope and also rotate in the direction it is moving since both are different axis the entity need to align to. But maybe i am just too stupid for it.
local world = World:GetCurrent()
local pickinfo = PickInfo()
local pivotPos = self.pivot:GetPosition()
local rayStart = Vec3(pivotPos.x, pivotPos.y+1, pivotPos.z)
local rayEnd = Vec3(rayStart.x, rayStart.y-50, rayStart.z)
if (world:Pick(rayStart,rayEnd,pickinfo,0.1,true,Collision.Scene)) then
local terrainNormal = pickinfo.normal
local pivotRotation = self.pivot:GetRotation(true)
self.entity:AlignToVector(terrainNormal, 1, 0.5, pivotRotation.y)
end
It seems no one else had an idea when i opened a forum post with that problem so i was stuck and searched for a different solution and found a more complicated one which worked for me.