After reading through [url]http://wiki.garrysmod.com/page/Entity_Driving[/url] and attempting to implement it, I left a comment.
I found this place, so I'm leaving this here as well.
Please help, I've spent about 8 hours trying to make code that will allow you to drive an entity with physics enabled.
I've been writing my own drive that will allow physics object motion, and move the object using AddForceCenter calls.
I've based all of this off of the given code. To be safe I copied driver_base into my lua above my custom one.
So far, I've gotten to where I have a physics object that will go in the direction I want, and will fall just like with gravity.
It has a few issues:
[B]#1, The player just sits where he went into the table (or any object, doesn't matter), and I cannot get his model to stop drawing.
#2, The camera shifts to a first person view of the object.
#3, Various drive_base issues[/B]
#2 means that calcview is not working correctly. After testing, it seems it isnt getting called. How can I get it to be called? I could call it from init, but init doesn't have the necessary view object.
Forcing CalcView to be called using CalcView() (no parameters... so it shouldn't work) led me to find that CalcView_ThirdPerson(...) was being found as 'nil'!
This leads to #3:
Using self:Stop() upon pressing 'E' doesn't work either. Since that and CalcView_ThirdPerson do not work, it means that drive_base is not being connected properly, or does not work itself. I have drive_base in the same folder as drive_prop_physics.
After taking the functionality out of both Stop() and CalcView_ThirdPerson() and placing it where each are called, they work.
However, for CalcView_ThirdPerson() I get that view is null. This makes sense, since I'm calling it from Init.
How is CalcView naturally called, or how can I get the proper view object to go in?
I would love some help :)
EDIT: Here is my current drive_prop_physics, which allows for physics movement of the prop and has all the above errors.
[CODE]AddCSLuaFile()
DEFINE_BASECLASS( "drive_base" );
drive.Register( "drive_prop_physics",
{
Init = function( self )
print("init")
self.Player:DrawWorldModel(false)
self.CameraDist = 4
self.CameraDistVel = 0.1
self:CalcView()
end,
CalcView = function( self, view )
local idealdist = math.max( 10, self.Entity:BoundingRadius() ) * self.CameraDist
print("calcview")
--self:CalcView_ThirdPerson( view, idealdist, 2, { self.Entity } )
local neworigin = view.origin - self.Player:EyeAngles():Forward() * idealdist
if ( hullsize && hullsize > 0 ) then
local tr = util.TraceHull( {
start = view.origin,
endpos = neworigin,
mins = Vector( 2, 2, 2 ) * -1,
maxs = Vector( 2, 2, 2 ),
filter = self.Entity
})
if ( tr.Hit ) then
neworigin = tr.HitPos
end
end
view.origin = neworigin
view.angles = self.Player:EyeAngles()
view.angles.roll = 0
end,
StartMove = function( self, mv, cmd )
self.Player:SetObserverMode( OBS_MODE_CHASE )
if ( mv:KeyReleased( IN_USE ) ) then
--self:Stop()
self.StopDriving = true
end
end,
Move = function( self, mv )
local speed = 0.0005 * FrameTime()
if ( mv:KeyDown( IN_SPEED ) ) then speed = 0.005 * FrameTime() end
local ang = mv:GetMoveAngles()
self.Entity:GetPhysicsObject():ApplyForceCenter(ang:Forward() * mv:GetForwardSpeed() * speed * 100)
self.Entity:GetPhysicsObject():ApplyForceCenter(Vector(0, 0, -9.8))
end,
FinishMove = function( self, mv )
if ( SERVER && IsValid( self.Entity:GetPhysicsObject() ) ) then
end
end,
}, "drive_base" );
[/CODE]
EDIT2: Clarity, Brevity
EDIT3: Solved the drivable entity not drawing, more clarity, brevity
EDIT6000: Clevarity
Sorry, you need to Log In to post a reply to this thread.