public void ApplyAntiRoll(Rigidbody rigidbody) { WheelHit hit = new WheelHit(); float travelL = 1.0f; float travelR = 1.0f; bool groundedL = wheelL.collider.GetGroundHit(out hit); if (groundedL) { travelL = (-wheelL.collider.transform.InverseTransformPoint(hit.point).y - wheelL.radius) / wheelL.collider.suspensionDistance; } bool groundedR = wheelR.collider.GetGroundHit(out hit); if (groundedR) { travelR = (-wheelR.collider.transform.InverseTransformPoint(hit.point).y - wheelR.radius) / wheelR.collider.suspensionDistance; } float antiRollForce = (travelL - travelR) * antiRollValue; if (groundedL) { rigidbody.AddForceAtPosition(wheelL.collider.transform.up * -antiRollForce, wheelL.collider.transform.position); } if (groundedR) { rigidbody.AddForceAtPosition(wheelR.collider.transform.up * antiRollForce, wheelR.collider.transform.position); } }
static public int AddForceAtPosition(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 3) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); UnityEngine.Vector3 a2; checkType(l, 3, out a2); self.AddForceAtPosition(a1, a2); return(0); } else if (argc == 4) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); UnityEngine.Vector3 a2; checkType(l, 3, out a2); UnityEngine.ForceMode a3; checkEnum(l, 4, out a3); self.AddForceAtPosition(a1, a2, a3); return(0); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static int AddForceAtPosition(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 3) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 3); obj.AddForceAtPosition(arg0, arg1); return(0); } else if (count == 4) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); UnityEngine.Vector3 arg1 = ToLua.ToVector3(L, 3); UnityEngine.ForceMode arg2 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 4, typeof(UnityEngine.ForceMode)); obj.AddForceAtPosition(arg0, arg1, arg2); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddForceAtPosition")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public override void OnFixedUpdate() { if (rigidbody != null) { rigidbody.AddForceAtPosition(owner.GetValue(force), owner.GetValue(position), forceMode); } Finish(); }
public void FixedUpdate() { if (KeepUpright) { // ***** USE TWO FORCES PULLING UP AND DOWN AT THE TOP AND BOTTOM OF THE OBJECT RESPECTIVELY TO PULL IT UPRIGHT *** // // *** THIS TECHNIQUE CAN BE USED FOR PULLING AN OBJECT TO FACE ANY VECTOR *** // _rigidbody.AddForceAtPosition(new Vector3(0, (UprightForce + AdditionalUpwardForce), 0), transform.position + transform.TransformPoint(new Vector3(0, UprightOffset, 0)), ForceMode.Force); _rigidbody.AddForceAtPosition(new Vector3(0, -UprightForce, 0), transform.position + transform.TransformPoint(new Vector3(0, -UprightOffset, 0)), ForceMode.Force); } if (DampenAngularForce > 0) { _rigidbody.angularVelocity *= (1 - Time.deltaTime * DampenAngularForce); } }
static public int AddForceAtPosition(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 5) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 3, out a1); UnityEngine.Vector3 a2; checkType(l, 4, out a2); UnityEngine.ForceMode a3; checkEnum(l, 5, out a3); self.AddForceAtPosition(a1, a2, a3); pushValue(l, true); return(1); } else if (argc == 4) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 3, out a1); UnityEngine.Vector3 a2; checkType(l, 4, out a2); self.AddForceAtPosition(a1, a2); pushValue(l, true); return(1); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <summary> /// makes this controller push a rigidbody using force or fixed velocity /// depending on the supplied 'PushForceMode'. in the 'Simplified' mode /// the controller will directly set the velocity of the rigidbody. /// in the 'Kinetic' mode force will be applied to the rigidbody at point /// of contact, and will accumulate. NOTE: 'point' will only have effect /// in 'Kinetic' mode. /// </summary> public void PushRigidbody(Rigidbody rigidbody, Vector3 moveDirection, PushForceMode pushForcemode, Vector3 point) { switch (pushForcemode) { case PushForceMode.Simplified: rigidbody.velocity = (vp_3DUtility.HorizontalVector((new Vector3(moveDirection.x, 0, moveDirection.z)).normalized) * (PhysicsPushForce / rigidbody.mass)); break; case PushForceMode.Kinetic: // if collision occurs beside (neither above nor below) the player we // will only apply horizontal force. this makes pushing stuff around // much smoother and easier if (Vector3.Distance(vp_3DUtility.HorizontalVector(Transform.position), vp_3DUtility.HorizontalVector(point)) > Player.Radius.Get()) { rigidbody.AddForceAtPosition(vp_3DUtility.HorizontalVector(moveDirection) * (PhysicsPushForce * KINETIC_PUSHFORCE_MULTIPLIER), point); // DEBUG: uncomment this to visualize horizontal push RPCs as green balls //GameObject o1 = vp_3DUtility.DebugBall(); //o1.renderer.material.color = Color.green; //o1.transform.position = point; } else { // if collision occured above or below the player we will apply force // along the unmodified collision vector. this makes for more realistic // physics when walking on top of stuff or bumping your head into it rigidbody.AddForceAtPosition(moveDirection * (PhysicsPushForce * KINETIC_PUSHFORCE_MULTIPLIER), point); // DEBUG: uncomment this to visualize vertical push RPCs as red balls //GameObject o2 = vp_3DUtility.DebugBall(); //o2.transform.position = point; } break; } }
// Use this for initialization void Start() { _rigidbody = gameObject.GetComponent<Rigidbody>(); _rigidbody.AddForceAtPosition(Vector3.up * Random.Range( 400f,900f), Random.insideUnitSphere * 2); }
public IEnumerator ApplyForce(Rigidbody body) { yield return new WaitForSeconds(.4f); Vector3 direction = body.transform.position - transform.position; body.AddForceAtPosition(direction.normalized, transform.position); }
void ApplyForce(Rigidbody body) { Debug.LogError("Wtf!"); Vector3 direction = body.transform.position - transform.position; body.AddForceAtPosition(direction.normalized, transform.position); }
public override void ApplyKillForce(Rigidbody rigidbody) { rigidbody.AddForceAtPosition(Force, Position, ForceMode.Impulse); }
public void FixedUpdate() { if (LeadTime == 0) { // ****** JUST PULL WITH TWO STRINGS TO FACE DIRECTION ***** // if (FacingDirection != Vector3.zero) { // ********************* FACE CHEST TOWARDS THE INPUT DIRECTION ******* _rigidbody.AddForceAtPosition(FacingForce * FacingDirection * Time.deltaTime, _rigidbody.transform.TransformDirection(BodyForward), ForceMode.Impulse); _rigidbody.AddForceAtPosition(-FacingForce * FacingDirection * Time.deltaTime, _rigidbody.transform.TransformDirection(-BodyForward), ForceMode.Impulse); } } else { // ******** TRY PULL TOWARDS DIRECTION FACTORING IN VELOCITY (ie. decelerate towards the target) *********** Vector3 targetPoint = transform.position + FacingDirection * BodyForward.magnitude; Vector3 currentPoint = transform.TransformPoint(BodyForward); Vector3 reversePoint = transform.TransformPoint(-BodyForward); Vector3 velocity = _rigidbody.GetPointVelocity(currentPoint); Vector3 diff = targetPoint - (currentPoint + velocity * LeadTime); _rigidbody.AddForceAtPosition(FacingForce * diff * Time.deltaTime, currentPoint, ForceMode.Impulse); _rigidbody.AddForceAtPosition(-FacingForce * diff * Time.deltaTime, reversePoint, ForceMode.Impulse); } }