• Angles of a normalized vector
    11 replies, posted
I've been messing around with vectors and angle a lot and have hit a mental roadblock. I'm trying to make a SENT that hovers a little bit above the ground (and moves like a vehicle, but first things first). The problem is that it will over at the wrong angles. I need it's pitch and roll to match the slant of the surface it's hovering over. Here's my trace code: [lua] // Trace down from the outter bounding radius local startTraceDown = ( self.Entity:GetPos() + self:OBBCenter() ) + ( self.Entity:GetVelocity():Angle():Forward() * self:BoundingRadius() ) local endTraceDown = startTraceDown + Vector(0,0,-1000) self.traceGroundNorm = util.QuickTrace( startTraceDown, endTraceDown, { self, ply } ) -- Trace the ground [/lua] I tried using the Angle function and RotateAroundAxis, but to no avail. How would I get the pitch/roll angles to match the ground below a SENT?
HitNormal will be perpendicular to the surface the trace hit. You want it to be parallel? What's wrong with rotating it? [lua]local angle = trace.HitNormal:Angle( ); angle:RotateAroundAxis( angle:Right( ), -90 );[/lua]
[QUOTE=Nevec;20192213]HitNormal will be perpendicular to the surface the trace hit. You want it to be parallel? What's wrong with rotating it? [lua]local angle = trace.HitNormal:Angle( ); angle:RotateAroundAxis( angle:Right( ), -90 );[/lua][/QUOTE] What about the roll?
The roll is already correct, you don't need to rotate it.
[QUOTE=MakeR;20192318]The roll is already correct, you don't need to rotate it.[/QUOTE] Oh. I thought I remembered reading somewhere that the roll gets taken out with some of these functions. I can't remember which one though.
-snip-
So will it do the roll for me?
Try it.
[code] entities/object_machine/init.lua:101: attempt to call method 'Angle' (a nil value) [/code] [lua] function ENT:Think() // Trace down from the outter bounding radius, starting at the front of it's current move vector local startTraceDown = ( self.Entity:GetPos() + self:OBBCenter() ) + ( self.Entity:GetVelocity():Angle():Forward() * self:BoundingRadius() ) local endTraceDown = startTraceDown + Vector(0,0,-1000) self.traceGroundNorm = util.QuickTrace( startTraceDown, endTraceDown, { self, ply } ) -- Trace the ground if self.traceGroundNorm.Hit then self.baseAngle = self.traceGroundNorm:Angle() self.baseAngle:RotateAroundAxis(self.baseAngle:Right(), -90) --This gets our pitch and roll to be parallel to the surface else self.baseAngle = self:GetAngles() self.baseAngle.pitch = 0 self.baseAngle.roll = 0 end end[/lua] Line 101 is line 7 here.
You are calling Angle() on the traceres table, You should be calling it on the HitNormal of the trace. [lua]self.BaseAngle = self.traceGroundNorm.HitNormal:Angle()[/lua]
[QUOTE=MakeR;20192916]You are calling Angle() on the traceres table, You should be calling it on the HitNormal of the trace. [lua]self.BaseAngle = self.traceGroundNorm.HitNormal:Angle()[/lua][/QUOTE] You're right. Silly me.
util.QuickTrace results a TraceResult structure and not an angle. [b]Edit:[/b] Damn :ninja:
Sorry, you need to Log In to post a reply to this thread.