Hi, while deriving from my vehicle base and it's PhysicsSimulate i get this error:
[code]
attempt to call method 'GetForward' (a nil value)
[/code]
Why is this? GetForward() is a valid function so why does not work when deriving from my base?
What object are you calling GetForward on? Angle, entity, vector? We could do with seeing some code.
[lua]
local ZAxis = Vector(0,0,1)
function ENT:PhysicsSimulate( phys, deltatime )--############## Flight code@ RononDex
local FWD = self:GetForward()
local UP = ZAxis
local RIGHT = FWD:Cross(UP):Normalize()
if(ValidEntity(self.Pilot)) then
if(self.Inflight) then
-- Accelerate
if((self.Pilot:KeyDown(self.Vehicle,"FWD"))and(self.Pilot:KeyDown(self.Vehicle,"SPD"))) then
num=self.BoostSpd
elseif((self.Pilot:KeyDown(self.Vehicle,"FWD"))) then
num=self.Speed
elseif(self.Pilot:KeyDown(self.Vehicle,"BACK")) then
num=-self.Speed
else
num=0
end
self.Accel.FWD=math.Approach(self.Accel.FWD,num,self.AccelerateSpd)
-- Strafe
if(self.Pilot:KeyDown(self.Vehicle,"RIGHT")) then
num2 = self.ManouverSpeed
elseif(self.Pilot:KeyDown(self.Vehicle,"LEFT")) then
num2 = -self.ManouverSpeed
else
num2=0
end
self.Accel.RIGHT=math.Approach(self.Accel.RIGHT,num2,self.AccelSpeed)
-- Up and Down
if(self.Pilot:KeyDown(self.Vehicle,"UP")) then
num3 = self.ManouverSpeed
elseif(self.Pilot:KeyDown(self.Vehicle,"DOWN")) then
num3 = -self.ManouverSpeed
else
num3=0
end
self.Accel.UP=math.Approach(self.Accel.UP,num3,self.AccelSpeed)
if(self.CanRoll) then
if(self.Pilot:KeyDown(self.Vehicle,"RL")) then
self.Roll = self.Roll - 5
elseif(self.Pilot:KeyDown(self.Vehicle,"RR")) then
self.Roll = self.Roll + 5
elseif(self.Pilot:KeyDown(self.Vehicle,"RROLL")) then
self.Roll = 0
end
end
phys:Wake()
if(not(self.Hover)) then
if self.Accel.FWD>-200 and self.Accel.FWD < 200 then return end --with out this you float
if self.Accel.UP>-200 and self.Accel.UP < 200 then return end
if self.Accel.RIGHT>-200 and self.Accel.RIGHT < 200 then return end
end
self.FlightPhys={
secondstoarrive = 1;
pos = self:GetPos()+(FWD*self.Accel.FWD)+(UP*self.Accel.UP)+(RIGHT*self.Accel.RIGHT);
maxangular = 9000;
maxangulardamp = 1000;
maxspeed = 1000000;
maxspeeddamp = 500000;
dampfactor = 1;
teleportdistance = 5000;
}
local ang = self.Pilot:GetAimVector():Angle()
local pos = self:GetPos()
local velocity = self:GetVelocity()
local aim = self.Pilot:GetAimVector();
local ang = aim:Angle();
local ExtraRoll = math.Clamp(math.deg(math.asin(self:WorldToLocal(pos + aim).y)),-25,25); -- Extra-roll - When you move into curves, make the shuttle do little curves too according to aerodynamic effects
local mul = math.Clamp((velocity:Length()/1700),0,1); -- More roll, if faster.
ang.Roll = (ang.Roll + self.Roll - ExtraRoll*mul) % 360;
self.FlightPhys.angle = ang --+ Vector(90 0, 0)
self.FlightPhys.deltatime = deltatime
self.Pilot:SetPos(pos);
phys:ComputeShadowControl(self.FlightPhys)
end
end
end
[/lua]
the speed vars are set in the derivative
[editline]02:39PM[/editline]
error occurs at [lua] local FWD = self:GetForward()[/lua]
Shouldn't it be self.Entity:GetForward() or something similar?
[QUOTE=whosdr;23251038]Shouldn't it be self.Entity:GetForward() or something similar?[/QUOTE]
Can't you use self instead of self.Entity
self:GetVelocity():Forward()?
Just tried using self.Entity and go this:
[code] attempt to index field 'Entity' (a nil value)
[/code]
[QUOTE=Ronon Dex;23251152]Just tried using self.Entity and go this:
[code] attempt to index field 'Entity' (a nil value)
[/code][/QUOTE]
You dont need self.Entity, its the same as self
In your previous thread you said you called self.BaseClass:PhysicsSimulate. That's where your problem's at.
[QUOTE=ralle105;23251804]In your previous thread you said you called self.BaseClass:PhysicsSimulate. That's where your problem's at.[/QUOTE]
so if i set local FWD in the derivative it should be fine?
self.BaseClass.PhysicsSimulate(self,phys,dt)
Ok, i have no errors now it just does not move. Gmod registers im pressing forward but the entity doesnt move. heres my code:
[lua]
local ZAxis = Vector(0,0,1)
function ENT:PhysicsSimulate( phys, deltatime )--############## Flight code@ RononDex
local FWD = self.Entity:GetForward()
local UP = ZAxis
local RIGHT = FWD:Cross(UP):Normalize()
if(not(ValidEntity(self.Pilot))) then return end
if(self.Inflight) then
-- Accelerate
if((self.Pilot:KeyDown(self.Vehicle,"FWD"))and(self.Pilot:KeyDown(self.Vehicle,"SPD"))) then
self.num=self.MaxSpeed
elseif((self.Pilot:KeyDown(self.Vehicle,"FWD"))) then
self.num=self.ForwardSpeed
print("pressing fwd")
elseif(self.Pilot:KeyDown(self.Vehicle,"BACK")) then
self.num=-self.ForwardSpeed
else
self.num=0
end
self.Accel.FWD=math.Approach(self.Accel.FWD,self.num,self.Accel.SpeedForward)
-- Strafe
if(self.Pilot:KeyDown(self.Vehicle,"RIGHT")) then
self.num2 = self.RightSpeed
elseif(self.Pilot:KeyDown(self.Vehicle,"LEFT")) then
self.num2 = -self.RightSpeed
else
self.num2=0
end
self.Accel.RIGHT=math.Approach(self.Accel.RIGHT,self.num2,self.Accel.SpeedRight)
-- Up and Down
if(self.Pilot:KeyDown(self.Vehicle,"UP")) then
self.num3 = self.UpSpeed
elseif(self.Pilot:KeyDown(self.Vehicle,"DOWN")) then
self.num3 = -self.UpSpeed
else
self.num3=0
end
self.Accel.UP=math.Approach(self.Accel.UP,self.num3,self.Accel.SpeedUp)
if(self.CanRoll) then
if(self.Pilot:KeyDown(self.Vehicle,"RL")) then
self.Roll = self.Roll - 5
elseif(self.Pilot:KeyDown(self.Vehicle,"RR")) then
self.Roll = self.Roll + 5
elseif(self.Pilot:KeyDown(self.Vehicle,"RROLL")) then
self.Roll = 0
end
end
phys:Wake()
if(not(self.Hover)) then
if self.Accel.FWD>-200 and self.Accel.FWD < 200 then return end --with out this you float
if self.Accel.UP>-200 and self.Accel.UP < 200 then return end
if self.Accel.RIGHT>-200 and self.Accel.RIGHT < 200 then return end
end
self.FlightPhys={
secondstoarrive = 1,
pos = self.Entity:GetPos()+(FWD*self.Accel.FWD)+(RIGHT*self.Accel.RIGHT)+(UP*self.Accel.UP),
maxangular = 9000,
maxangulardamp = 1000,
maxspeed = 1000000,
maxspeeddamp = 500000,
dampfactor = 1,
teleportdistance = 5000,
}
local ang = self.Pilot:GetAimVector():Angle()
local pos = self.Entity:GetPos()
local velocity = self.Entity:GetVelocity()
local aim = self.Pilot:GetAimVector();
local ang = aim:Angle();
local ExtraRoll = math.Clamp(math.deg(math.asin(self:WorldToLocal(pos + aim).y)),-25,25); -- Extra-roll - When you move into curves, make the shuttle do little curves too according to aerodynamic effects
local mul = math.Clamp((velocity:Length()/1700),0,1); -- More roll, if faster.
ang.Roll = (ang.Roll + self.Roll - ExtraRoll*mul) % 360;
self.FlightPhys.angle = ang --+ Vector(90 0, 0)
self.FlightPhys.deltatime = deltatime
self.Pilot:SetPos(pos);
phys:ComputeShadowControl(self.FlightPhys)
print("PhysicsSimulate run")
end
end
[/lua]
All the number vars(E.G self.ForwardSpeed) are in the derivative
Sorry, you need to Log In to post a reply to this thread.