I asked in the newbie questions forum, but since this apparently is not simple I’ll ask here. Right now I’m using **[PhysObj.ComputeShadowControl
http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=PhysObj.ComputeShadowControl)** inside of the **[ENT.PhysicsSimulate
Here’s what I’m trying to do: My SENT is like a vehicle of sorts, but it cruises at a set distance above the ground, except when it goes off of ledges, in which case you can glide (fly). Right now I’m working on the cruising aspect. The SENT has several variables that alter how the movement works.
[li]Speed[/li]This is the constant speed that the entity tries to achieve unless told otherwise.
[li]Acceleration[/li]This is in units per second. It does not effect the enitity’s speed after it has reached its desired speed.
[li]Turn[/li]This is how fast the entity turns when the player presses their strafe keys. It is in degrees per second.
[li]Handling[/li]This is where things get tricky. I’ll try and explain this as best I can.
Handling determines how quickly the current move vector changes to the one that the player is trying to move in based on current speed. The turn variable and the handling variable do not effect one another, but they do combine to represent the control the player has over the vehicle. In other words, Turn + Handling = Control.
Here are some examples of how this would work:
[list][li]High turn + low handling = Spinning around when turning while sliding in your current move vector.[/li][li]Low turn + high handling = Very gradual turning.[/li][li]High turn + high handling = Moving and turning exactly where you intend to.[/li][li]Low turn + low handling = No control at all.[/ul][/li]Most of the time, the mix will be somewhere in between. I’m just using extremes so you get the picture.
[li]Glide[/li]This one is dependant on the input of the forward/back keys. Forward means aim down, back means aim up. The number here determines how high and far we can glide, the degrees of pitch change per second, the maximum upward pitch before no longer travelling forward and up, our speed and acceleration in air, and the amount of time it takes before descent. All of this is also in direct relation to the previous values presented.
Now that you understand the issue (I hope), it’s time for the math, which is what I suck at.
Here’s what I have so far:
function ENT:PhysicsSimulate( phys, delta )
phys:Wake() local ply = self.Rider -- Our player controlling the SENT local turn, speed if self.Rider then turn, speed = --This is what I need to find... else return SIM_NOTHING end local accel = 5 --Our acceleration local maxspeed = 25 --Our speed local curvec = speed or self:GetVelocity() --Our current speed if curvec:Length() >= maxspeed then accel = 1 end local newpos = (curvec*delta) + speed * (0.5 * accel * (delta^2)) --Our next position to move to local dist = (self:GetPos() - newpos):Length() local sta = self:GetVelocity():Length()/dist --seconds to arrive self.ShadowParams.secondstoarrive = sta // 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 = newpos // Where you want to move to self.ShadowParams.angle = turn // Angle you want to move to self.ShadowParams.maxangular = 1 // What should be the maximal angular force applied self.ShadowParams.maxangulardamp = 3 // At which force/speed should it start damping the rotation self.ShadowParams.maxspeed = 4 // Maximal linear force applied self.ShadowParams.maxspeeddamp = 5 // 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 = 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)
In short, none of this works yet. I haven’t a clue as to how to make all of the ShadowParams work cohesively.
Anyone know how I can achieve this kind of movement I’ve described?