this is from the rigidbody FPS script with air control thats some where on this forum, im having a problem controling this part which is the air control Code (csharp): // Add in air targetVelocity = new Vector3(0, 0, Input.GetAxis("Horizontal")); targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl; rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange); i dont want the velocity to ever go past 180 as a result of using the air control, but other things like being hit do make my char go that fast, so i cant just say somthing like if(velocity>180){velocity=180}, and when i tried that it also didnt slow down the acceleration, it just made a sudden jerky stop when it got to 180 the problem with this air control is it will just keep on accelerating, but if i put the inaircontrol var low enough where this wouldn't happen , the aircontrol becomes so sluggish its not useful ive been yelling at my moniter for an hour and i would really appriciate some help
I dunno if this is an appropriate answer, but if you have sufficent drag on your rigidbody, wont that cap your acceleration? This wont give you easy access to cap it at exactky 180, but by trial and error you might get a satisfactory result? HTH AC
Only an hour? I find getting controls right to be one of the harder things left to do when using Unity. Try increasing the drag to a high number when the velocity goes above your magic number, or increasing the drag only when the air control buttons are pressed. (Then returning it back down when the condition is no longer met) I've found when trying to get a rigidbody's controls to "feel" right, you need to liberally apply drag and high force values appropriately to get control precision and snappyness, but not let velocities get ridiculous. Tweak liberally. Cheers, -Jon
agreed... it sounds so much easier on paper... the problem is if i raise the drag he starts to fall slower which looks really weird, so i have to find a way to tell it if the target velocity your trying to reach is greater than 180, than try to get to just 180 instead, but i dont understand the stuff in that code so im havin a hard time
Code (csharp): // Add in air if (targetVelocity >= 180) { targetVelocity = 180; } else { targetVelocity = new Vector3(0, 0, Input.GetAxis("Horizontal")); targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl; rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange); }
whoops! guess i wrote that without reading! yeah that would happen and there's more problems than that in what i wrote. ignore that whole snippet... what are you doing with the rest of your code - where does inAirControl come from? can you do something like Code (csharp): var speed = 180.0; inAirControl = speed * Input.GetAxis("Horizontal"); then for targetVelocity just Code (csharp): targetVelocity = new Vector3.forward; or even simpler... Code (csharp): var speed = 180.0; // Add in air targetVelocity = new Vector3.forward; targetVelocity = transform.TransformDirection(targetVelocity) * speed * Input.GetAxis("Horizontal"); rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange);
that code is being used in an else statement that happens if it isnt touching the ground, and i dont know why but unity is having a problem with tht code you posted, it says its missing a semicolon but its not, and i cant tell where its having the problem
looking at it again, you might want to change it back to... Code (csharp): var speed = 180.0; // Add in air targetVelocity = new Vector3.(0,0,Input.GetAxis("Horizontal")); targetVelocity = transform.TransformDirection(targetVelocity) * speed; rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange); not sure it really matters. just seems cleaner to me. it makes targetVelocity.z between -1 and 1 rather than always 1 and multiplying with values between -1 and 1. when i've seen the semicolon thing it's usually because something is whacked in the script. usually not the line it points to but something else i did above it. tough to track down (or really know what you're trying to do) without seeing the whole script.