Best way to do that would be an upward applyForce to negate the chip's gravity. With gravity negated by the force, the chip would hover in place, not unlike in a vacuum.
I want to let my E2 chip hover at its own altitude, although I want to grab it and reposition his position without him flying back to his old location.
It's for a E2 camera im working on, it's controlled by mouse. and I want to put a thruster on it so I can fly around freely.
Best way to do that would be an upward applyForce to negate the chip's gravity. With gravity negated by the force, the chip would hover in place, not unlike in a vacuum.
gravity works through vacuums :P
if your not sure on the code, you would need to do something along the lines of
Code:applyforce(Prop:up() * Prop:mass() * gravity())
No, if the plate was upside down it would just apply downward force, this is the code (Working as I've made it before):
Code:@inputs Ent:entity runOnTick(1) Ent:applyForce(vec(0, 0, 9.8)*Ent:mass())
9.81 is gravity. on earth. at sea level. in this universe.
Gmod gravity is not 9.81
Gmod gravity is whatever sv_gravity is.. Which is 600 normally.
There should be an automatic kick in the butt when someone uses "9.8" in a post, when "gravity" is mentioned in the thread on wiremod.com.
edit: *Kick*
Unfortunately gravity, acceleration, force, etc does *NOT* work how it should in gmod. Even if you use a figure like 600 somewhere in your calculations, it won't work... I've tried MANY times. There is, however, an upward force needed to counteract gravity for a given mass. I tried to get a formula for this, but it jumps around and is pretty damn erratic. If you have, like you say a camera, you only have to calculate this force once. Something like this:
e2 Code:
@inputs Ent:entity @persist Calibration runOnTick(1) Calibration += entity():vel():z() EE:applyForce(Calibration*vec(0,0,1))
It will struggle a bit but it will eventually get there. You might want to mess with a multiplier or something on Calibration. Obviously, do this with gravity on. Once it settles and stops moving up and down, save the number using a debugger or something.
You could probably just make one E2 that does this and change the E2 to the weight of the prop you'll end up using + 1 for the weight of the expression that I assume you'll be attaching to said prop.
But when I came into this topic I was thinking about another way to do it.
e2 Code:
@inputs ENT runOnTick(1) Held = entity():owner:isBeingHeld() #I'm not really sure of the function, whatever tells you if its being frozen or not Pos = ENT:pos() SomeMultiplier = ??? if((~Held & !Held) | first()) #if someone just stopped holding it {HoldPos = Pos} #make that position it stopped being held at the position to stick to ENT:applyForce(SomeMultiplier*(HoldPos - Pos - ENT:vel())
Hope this helps.
EDIT: Forgot about adding in the air friction part of it.
Last edited by mjmr89; 05-07-2009 at 03:47 PM.
Some code im using atm is
works like a charm, all you need to do is find the correct multiplyer and your there, dunno where i got 5 from lol thats just from code i took from Paper Clip to fiddle around with some stuff.Code:Force = (TargetPos - Prop:pos()) * 5 - Prop:vel() Force *= Prop:mass() Prop:applyForce(Force)
Just do something like
applyForce(-entity():vel()*entity():mass())
Bookmarks