tr.HitNormal and Angles

I’m trying to make a vehicle-type thing that will always be 100 units and in line with the surface below it. Here’s the code here’s the code i have so far:

[lua]function ENT:PhysicsSimulate( phys, deltatime )

	local track = nil
	for _,v in ipairs(ents.FindInSphere(self.Entity:GetPos(),200)) do
		if v:GetClass() == "env_track" then track = v end
	if !track then return end
	local tracktr = util.TraceLine({start = self.Entity:GetPos(),endpos = self.Entity:GetPos() - self.Entity:GetUp() * 200,filter=self.Entity})

		if self.Pilot:KeyDown(IN_FORWARD) then self.Accel = math.Approach(self.Accel,2000,4.5)
		else self.Accel = math.Approach(self.Accel,0,-4.5) end

	local pr={}
		pr.pos				= self.Entity:GetPos()+self.Entity:GetForward()*self.Accel + tracktr.HitNormal * (180 - self.Entity:GetPos():Distance(tracktr.HitPos))

		local fwd = self.Entity:GetForward()
		local hit = tracktr.HitNormal
		self.Angle = fwd:Angle()		
		if self.Pilot:KeyDown(IN_MOVERIGHT) then
			self.Angle = self.Angle - Angle(0,40,0)
			pr.pos = pr.pos + self.Entity:GetRight() * 100
		elseif self.Pilot:KeyDown(IN_MOVELEFT) then
			self.Angle = self.Angle + Angle(0,40,0)
			pr.pos = pr.pos - self.Entity:GetRight() * 100
		self.Angle.pitch = 270 - hit:Angle().pitch
		pr.angle = self.Angle		



This is a shortened version. So, what I tried to do was set self.Angle to tracktr.HitNormal:Angle(). Unfortunately, while it kept me in the right direction on the x/y, it never changed my pitch.

Also, when I went on a track where it was rolled left or right, it kind of sort of works but it’s aimed the wrong way.

Here’s some pics:

Regular surface, works fine.

Sloped surface, not so much. Very spazzy.

Roll-d surface, works kinda ok but not great. (pic shows me turning so I can give you a view of the track)


Please, I need help here. :frowning:

Looks like a nice project. Shame I cannot help fix it, I have not used Shadow Control before. Good luck!