• func_movelinear - linear smoothed out motion on a prop
    3 replies, posted
Hey, I have been trying to create something for out community, or rather, recreate something - There was this server, that had smuggling system that worked like this: On a certain map, sometimes there was a train coming into the map with a payload on it, people could smuggle boxes full of shipments off it. I am trying to recreate this - everything else is planned out and soon I'll make other of its parts, but right now I am stuck on trains movement. See, I have managed make the train prop sliding through the coordinates I told it to just fine using linear interpolation and setting its pos, but that doesn't hit the sweet spot - the issue is, when player stands on top of the train, then that player just stands on and eventually slides on (he's not changing his pos alongside with train), I want him to be "carried" by the prop as well. After some research, I've found func_movelinear to be the thing I need. Thing is, I have no idea how to create that type of entity code-wise, all I've seen is tutorials how to create that entity in hammer editor, but not in Lua. You know the way that elevators in source engine move with smooth motion and are able to crush or carry things with them? Yep, I want that, in the current state the prop just phases through because its position is being SET forcefully. Has anyone got a func_movelinear tutorial? Or examples? Or can I achieve that effect in any other way? This is the code I am using (positions are set so they are correct for the rp_downtown_wars_v1 map - use command /lerpthis to be teleported and look exactly at the surfing prop) Serverside. [code] if game.GetMap() != "rp_downtown_wars_v1" then return end local entity = nil local behindpos = Vector(-3000.610840, 1865.731201, -436.968750) --Destination local function lerpthis(ply,text) if ply:Alive() and string.lower(text) == "/lerpthis" then entity = ents.Create("prop_physics") entity:SetModel("models/props_trainstation/train001.mdl") entity:SetPos(Vector(1231.723511, 1865.731201, -436.968750)) entity:SetAngles(Angle(0,90,0)) --starting pos and angle entity:Spawn() entity:SetMoveType(MOVETYPE_PUSH) ply:SetPos(Vector(-1181.073853, 1785.168457, -420.968750)) ply:SetAngles(Angle(1.636754, 0.913886, 0.000000)) return "" end end hook.Add("PlayerSay","LerpingTest",lerpthis) hook.Add("Think","LerpMe",function() if IsValid(entity) then local pos = LerpVector(0.3*FrameTime(),entity:GetPos(),behindpos) entity:SetAngles(Angle(0,90,0)) entity:SetPos(pos) if entity:GetPos():Distance(behindpos) <= 100 then entity:Remove() entity = nil end end end) [/code]
The problem is that SetPos is basically teleporting the object, you have to use something like this: [url]http://wiki.garrysmod.com/page/PhysObj/ComputeShadowControl[/url]
Yeah, thanks I'll try that! [editline]28th March 2017[/editline] Yep, can't get it to work. Should I create entire new ent for this? Is prop_physics not anim type entity? My code: [code] if game.GetMap() != "rp_downtown_wars_v1" then return end local entity = nil --local behindpos = Vector(-3000.610840, 1865.731201, -436.968750) --Destination local function lerpthis(ply,text) if ply:Alive() and string.lower(text) == "/lerpthis" then entity = ents.Create("prop_physics") entity:SetModel("models/props_trainstation/train001.mdl") entity:SetPos(Vector(1231.723511, 1865.731201, -436.968750)) entity:SetAngles(Angle(0,90,0)) --starting pos and angle entity:Spawn() entity:StartMotionController() entity.ShadowParams = {} entity:SetMoveType(MOVETYPE_PUSH) function entity:PhysicsSimulate(phys,deltatime) phys:Wake() self.ShadowParams.secondstoarrive = 8 // How long it takes to move to pos and rotate accordingly - only if it could move as fast as it want - damping and max speed/angular will make this invalid ( Cannot be 0! Will give errors if you do ) self.ShadowParams.pos = Vector(-3000.610840, 1865.731201, -436.968750) // Where you want to move to self.ShadowParams.angle = Angle(0,90,0) // Angle you want to move to self.ShadowParams.maxangular = 5000 //What should be the maximal angular force applied self.ShadowParams.maxangulardamp = 10000 // At which force/speed should it start damping the rotation self.ShadowParams.maxspeed = 1000000 // Maximal linear force applied self.ShadowParams.maxspeeddamp = 10000// Maximal linear force/speed before damping self.ShadowParams.dampfactor = 0.8 // The percentage it should damp the linear/angular force if it reaches it's max amount self.ShadowParams.teleportdistance = 200 // If it's further away than this it'll teleport ( Set to 0 to not teleport ) self.ShadowParams.deltatime = deltatime // The deltatime it should use - just use the PhysicsSimulate one phys:ComputeShadowControl( self.ShadowParams ) end -- here it ends ply:SetPos(Vector(-1181.073853, 1785.168457, -420.968750)) ply:SetAngles(Angle(1.636754, 0.913886, 0.000000)) return "" end end hook.Add("PlayerSay","LerpingTest",lerpthis) --[[hook.Add("Think","LerpMe",function() if IsValid(entity) then local pos = LerpVector(0.3*FrameTime(),entity:GetPos(),behindpos) entity:SetAngles(Angle(0,90,0)) entity:SetPos(pos) if entity:GetPos():Distance(behindpos) <= 100 then entity:Remove() entity = nil end end end)]]-- [/code] I do realise it might be completely wrong. Thanks in advance :)
did a new entity, and I did it like everyone else did thanks for dem help friends solved
Sorry, you need to Log In to post a reply to this thread.