Question by
finalzesty · Apr 25, 2019 at 11:24 AM ·
c#programmingalternativeprogramingrewriting
So im looking to rewrite this set of code
so have this code from online where I'm learning to limit this drone movement using this tutorial ("https://youtu.be/UghcAU0dsGI") so I'm trying to rewrite this just to make it shorter and easier to complete, but I don't get what clamping speed or magnitudes are, can someone help me understand what's going on in this code provided below and also tell me if there is an alternative to this, thanks
Code: private Vector3 velocityTosmoothdamptoZero; void ClampingSpeedValue() { if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f){ Drone.velocity = Vector3.ClampMagnitude(Drone.velocity, Mathf.Lerp(Drone.velocity.magnitude, 10.0f, Time.deltaTime * 5f)); }
if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f){
Drone.velocity = Vector3.ClampMagnitude(Drone.velocity, Mathf.Lerp(Drone.velocity.magnitude, 10.0f, Time.deltaTime * 5f));
}
if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f){
Drone.velocity = Vector3.ClampMagnitude(Drone.velocity, Mathf.Lerp(Drone.velocity.magnitude, 5.0f, Time.deltaTime * 5f));
}
if (Mathf.Abs(Input.GetAxis("Vertical")) < 0.2f && Mathf.Abs(Input.GetAxis("Horizontal")) < 0.2f){
Drone.velocity = Vector3.SmoothDamp(Drone.velocity, Vector3.zero, ref velocityTosmoothdamptoZero, 0.95f);
}
}
Comment