phys:ComputeShadowControl sends ent 7.1998 below target?
3 replies, posted
I copied this code mostly from the wiki, but it always sends my ent lower than the target destination.
Anyone know why?
[lua]ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Dynamic Mesh Point"
ENT.Author = "Lexi"
ENT.Contact = ""
ENT.Purpose = ""
ENT.Instructions = ""
ENT.Information = ""
ENT.Category = "Util"
ENT.Spawnable = true
ENT.AdminSpawnable = true
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT;
function math.DecimalPlaces(numb,places)
return math.Round(numb*10^places)/10^places
end
if SERVER then
AddCSLuaFile"shared.lua"
AddCSLuaFile"cl_init.lua"
function ENT:SpawnFunction( ply, tr )
if not tr.Hit then return end
local ent = ents.Create("sent_mesh")
ent:SetPos( tr.HitPos + tr.HitNormal * 50--
)
ent:Spawn()
ent:Activate()
local phys = ent:GetPhysicsObject()
if (phys:IsValid()) then
phys:EnableMotion(true)
phys:Wake()
end
return ent
end
function ENT:Initialize()
self.Entity:SetModel("models//props_junk/Rock001a.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS)
self.Entity:SetMoveType( MOVETYPE_VPHYSICS)
self.Entity:SetSolid( SOLID_VPHYSICS)
self.Entity:SetUseType(SIMPLE_USE)
self.Entity:DrawShadow(false)
self.MovinTooFast = false
self.ShadowParams = {}
self.TargetPos = Vector(0,0,0)
end
function ENT:Use(activator,caller)
if not activator:IsPlayer() then return end
if self.MovinTooFast then
self:StopMotionController()
self.MovinTooFast = nil
else
self:StartMotionController()
self.MovinTooFast = true
end
end
function ENT:PhysicsSimulate(phys,delta)
phys:Wake()
if self:GetPos() == self.TargetPos then
self:StopMotionController()
self.MovinTooFast = nil
MsgN"DESTINATION"
return
end
print(self:GetPos())
self.ShadowParams.secondstoarrive = 1 // How long it takes to move to pos and rotate accordingly - only if it _could_ move as fast as it want - damping and maxspeed/angular will make this invalid
self.ShadowParams.pos = self.TargetPos // Where you want to move to
self.ShadowParams.angle = Angle( 0, 0, 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.2 // The percentage it should damp the linear/angular force if it reachs it's max ammount
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)
end
return
end
local width = 10
local Laser = Material( "cable/redlaser" )
function ENT:Draw()
self.Entity:DrawModel()
end[/lua]
[code]
33.3103 11.1297 -143.4837
32.8287 10.9714 -141.3835
32.4728 10.9432 -139.2306
32.3106 11.0595 -137.4686
32.2350 11.1626 -136.2211
32.2565 11.3402 -135.1667
32.3789 11.6491 -134.0797
32.5806 12.0774 -132.8972
32.8628 12.6454 -131.5065
33.2000 13.3134 -129.9361
32.9905 13.6575 -126.8621
32.3412 13.7326 -122.6189
31.3506 13.5905 -117.5062
30.1024 13.2760 -111.7768
28.6672 12.8271 -105.6417
27.1041 12.2766 -99.2749
25.4620 11.6523 -92.8185
23.7806 10.9776 -86.3870
22.0924 10.2720 -80.0710
20.4231 9.5519 -73.9410
18.7929 8.8306 -68.0502
17.2175 8.1190 -62.4377
15.7084 7.4256 -57.1305
14.2740 6.7571 -52.1456
12.9199 6.1186 -47.4919
11.6494 5.5137 -43.1717
10.4640 4.9450 -39.1819
9.3638 4.4137 -35.5153
8.3476 3.9206 -32.1613
7.4131 3.4656 -29.1070
6.5576 3.0480 -26.3377
5.7776 2.6668 -23.8374
5.0695 2.3205 -21.5894
4.4289 2.0077 -19.5766
3.8519 1.7263 -17.7819
3.3340 1.4745 -16.1884
2.8709 1.2503 -14.7794
2.4584 1.0516 -13.5390
2.0925 0.8763 -12.4521
1.7691 0.7225 -11.5041
1.4845 0.5884 -10.6813
1.2350 0.4719 -9.9710
1.0173 0.3715 -9.3613
0.8283 0.2854 -8.8412
0.6648 0.2121 -8.4005
0.5243 0.1503 -8.0299
0.4041 0.0984 -7.7210
0.3021 0.0555 -7.4660
0.2160 0.0203 -7.2580
0.1439 -0.0082 -7.0907
0.0840 -0.0308 -6.9585
0.0349 -0.0484 -6.8563
-0.0049 -0.0617 -6.7796
-0.0367 -0.0714 -6.7246
-0.0616 -0.0780 -6.6876
-0.0807 -0.0821 -6.6657
-0.0948 -0.0841 -6.6562
-0.1047 -0.0843 -6.6567
-0.1111 -0.0832 -6.6652
-0.1146 -0.0811 -6.6800
-0.1157 -0.0780 -6.6996
-0.1150 -0.0744 -6.7228
-0.1127 -0.0704 -6.7484
-0.1092 -0.0660 -6.7757
-0.1048 -0.0615 -6.8039
-0.0998 -0.0570 -6.8324
-0.0943 -0.0524 -6.8606
-0.0885 -0.0480 -6.8883
-0.0826 -0.0437 -6.9151
-0.0767 -0.0396 -6.9408
-0.0708 -0.0356 -6.9653
-0.0651 -0.0320 -6.9883
-0.0596 -0.0285 -7.0099
-0.0543 -0.0253 -7.0299
-0.0493 -0.0224 -7.0485
-0.0445 -0.0197 -7.0656
-0.0401 -0.0172 -7.0813
-0.0360 -0.0150 -7.0955
-0.0321 -0.0130 -7.1085
-0.0286 -0.0112 -7.1202
-0.0254 -0.0095 -7.1308
-0.0224 -0.0081 -7.1403
-0.0197 -0.0068 -7.1487
-0.0173 -0.0057 -7.1562
-0.0151 -0.0047 -7.1629
-0.0131 -0.0038 -7.1688
-0.0113 -0.0031 -7.1739
-0.0097 -0.0024 -7.1784
-0.0083 -0.0019 -7.1823
-0.0071 -0.0014 -7.1857
-0.0060 -0.0010 -7.1886
-0.0050 -0.0007 -7.1911
-0.0042 -0.0004 -7.1933
-0.0034 -0.0002 -7.1951
-0.0028 0.0000 -7.1966
-0.0022 0.0002 -7.1978
-0.0017 0.0003 -7.1988
-0.0013 0.0004 -7.1997
-0.0010 0.0004 -7.2003
-0.0007 0.0005 -7.2009
-0.0004 0.0005 -7.2013
-0.0002 0.0005 -7.2016
-0.0001 0.0005 -7.2018
0.0001 0.0005 -7.2019
0.0002 0.0005 -7.2020
0.0002 0.0005 -7.2020
0.0003 0.0005 -7.2020
0.0004 0.0004 -7.2020
0.0004 0.0004 -7.2019
0.0004 0.0004 -7.2018
0.0004 0.0004 -7.2017
0.0004 0.0003 -7.2016
0.0004 0.0003 -7.2015
0.0004 0.0003 -7.2014
0.0004 0.0003 -7.2013
0.0004 0.0002 -7.2012
0.0003 0.0002 -7.2010
0.0003 0.0002 -7.2009
0.0003 0.0002 -7.2008
0.0003 0.0002 -7.2007
0.0003 0.0001 -7.2006
0.0002 0.0001 -7.2005
0.0002 0.0001 -7.2005
0.0002 0.0001 -7.2004
0.0002 0.0001 -7.2003
0.0002 0.0001 -7.2003
0.0001 0.0001 -7.2002
0.0001 0.0001 -7.2001
0.0001 0.0000 -7.2001
0.0001 0.0000 -7.2000
0.0001 0.0000 -7.2000
0.0001 0.0000 -7.2000
0.0001 0.0000 -7.1999
0.0001 0.0000 -7.1999
0.0000 0.0000 -7.1999
0.0000 0.0000 -7.1999
0.0000 0.0000 -7.1999
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 0.0000 -7.1998
0.0000 -0.0000 -7.1998
0.0000 -0.0000 -7.1998
0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 -0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
-0.0000 0.0000 -7.1998
[/code]
[lua]self.ShadowParams.deltatime = deltatime[/lua]
Shouldn't it be = delta, since that's how you named your parameter in PhysicsSimulate?
Also, if that doesn't work, try disabling gravity while the motion controller is active.
Ok, disabling gravity worked, and now it stops 1.9392429884135e-009 below 0,0,0. While this is an infinitesimally small amount, it doesn't quite == Vector(0,0,0) which screws up my equality check a bit.
*Sigh*
On a side note, what [i]is[/i] delta time?
[QUOTE=Lexic;17192148]Ok, disabling gravity worked, and now it stops 1.9392429884135e-009 below 0,0,0. While this is an infinitesimally small amount, it doesn't quite == Vector(0,0,0) which screws up my equality check a bit.
*Sigh*
On a side note, what [i]is[/i] delta time?[/QUOTE]
Physics is never perfect, so you will never get exactly Vector(0,0,0). Just give it some tolerancy on each axis, 0.1 should do nicely.
Also, delta time is the time between each physics calculation. Basically, it's here so the physics always behave the same regardless of your framerate.
Sorry, you need to Log In to post a reply to this thread.