• UpdateShadow
    6 replies, posted
Hey, recently I have made a thread about helping me moving stuff from point A to point B smoothed out, keeping its physics - Zeh Matt helped me by hinting me to ComputeShadowControl - while it worked, I wasn't happy with the result. I didn't like damping applied and turns out I can't get rid of it, so I looked around and my research threw me here: [url]https://wiki.garrysmod.com/page/PhysObj/UpdateShadow[/url] Thing is, whenever I try to the entity remains in the same place no matter what, it has became static - seems like initiating physics as a physics shadow for me freezes completely the ent. Here's the ent: UpdateShadow doesn't do anyt [code] AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') sound.Add({ name = "trainwheels", channel = CHAN_STREAM, volume = 0.4, level = 85, pitch = 100, sound = "ambient/machines/train_wheels_loop1.wav"}) function ENT:Initialize() self:SetModel( self.model ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_VPHYSICS ) self:SetSolid( SOLID_VPHYSICS ) self.children = {} self:PhysicsInitShadow(true,true) local phys = self:GetPhysicsObject() if (phys:IsValid()) then constraint.NoCollide(self,game.GetWorld(),0,0) phys:EnableGravity(false) self:SetCustomCollisionCheck( true ) self.ShadowParams = {} self:EmitSound("trainwheels") timer.Simple(2,function() if IsValid(self) then sound.Play( "ambient/machines/train_horn_3.wav", self:GetPos(), 100, 100, 1 ) end end) end end function ENT:Think() if self:GetPos():Distance(self.destination) <= 50 then self:Remove() end end function ENT:OnRemove() self:StopSound("trainwheels") for i,k in pairs(self.children) do k:Remove() end end function ENT:PhysicsSimulate( phys, deltatime ) --[[self.ShadowParams.secondstoarrive = self.time or 5 // 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 = self.destination or self:GetPos() // Where you want to move to self.ShadowParams.angle = self.destinationang // 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 = 100000 // Maximal linear force applied self.ShadowParams.maxspeeddamp = 10000// Maximal linear force/speed before damping --self.ShadowParams.dampfactor = 1 // The percentage it should damp the linear/angular force if it reaches it's max amount self.ShadowParams.teleportdistance = 0 // 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 )]]-- phys:UpdateShadow( self.destination, self.destinationang, deltatime ) end [/code]
Did you call [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/StartMotionController]Entity:StartMotionController[/url]?
Oh shit, seems like at some point I removed it and completely forgot about it. Now the thing is, if I set the movement this way - it doesn't seem to run over the player and kill him - and train seems to "slow down" or "stop" for a split second fucking everything up, because there are wagons behind it that then morph into the first wagon (or whatever it is called). So in short, if I touch any entity that is driven that way, it actually slows it down and because of that entities behind it morph into it because they retained their initial speed. Also, the movement still seems to slow down at the end, could you show me other ways of doing it? Linear, constant speed is my goal :) [code] function ENT:PhysicsSimulate( phys, deltatime ) phys:Wake() local smooth = Lerp(FrameTime()/5,self:GetPos(),self.destination) phys:UpdateShadow( smooth, self.destinationang, deltatime/self.time ) end [/code] edit: should I just parent the rest of the wagons, weld it, or just leave it like that? (Follow the same route, with the same speed, but move the destination a little bit)
Fixed the issue of players colliding, turned out I should've just done it like that: I just haven't solved that the speed is being constantly damped - just before reaching the destination speed value starts to drop, which is really annoying because I am aiming for steady, constant speed of it. [code]phys:UpdateShadow( smooth, self.destinationang, 10 ) -- Or whatever time I want to put here [/code]
bump, I still need help with having the speed constant, not slowly decreasing before destination is met. [code]phys:UpdateShadow( self.destination, self:GetAngles(), self.time )[/code]
[lua] function ENT:PhysicsSimulate( phys, deltatime ) phys:Wake() local dir = (self.destination - self:GetPos()):GetNormalized() phys:UpdateShadow(self:GetPos() + dir*100, self.destinationang, deltatime ) end [/lua] untested
Holy shit, you are an absolute madman! That helped me so much! Loving the solution, still trying to wrap myself around normalized vectors, but that helped me a lot! Marking as solved :)
Sorry, you need to Log In to post a reply to this thread.