public void applyLinearForce(Rigidbody toBody, Vector3 desiredForce, bool relative) { if(relative) toBody.AddRelativeForce (desiredForce, this.forceMode); else toBody.AddForce (desiredForce, this.forceMode); }
void Go() { float throwForce = 0; //Aims grenade at Target if (hasTarget) { float xDist = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(target.x, target.z)); float yDist = -(transform.position.y - target.y); //Calculate force required throwForce = xDist / (Mathf.Sqrt(Mathf.Abs((yDist - xDist) / (0.5f * (-Physics.gravity.y))))); throwForce = 1.414f * throwForce / Time.fixedDeltaTime * GetComponent<Rigidbody>().mass; //Always fire on a 45 degree angle, this makes it easier to calculate the force required. transform.Rotate(-45, 0, 0); } myRigidBody = GetComponent<Rigidbody>(); myRigidBody.AddRelativeForce(Vector3.forward * throwForce); //Start the time on the grenade StartCoroutine(StartDetonationTimer()); //Because the grenade may skim the colliders of the agent before detonating, we want to wait a moment or two before being able to "warn" agents of the grenade //Warning will cause surrounding agents to attempt to escape from the grenade. StartCoroutine(SetTimeUntilWarning()); }
static public int AddRelativeForce(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 5) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); System.Single a3; checkType(l, 4, out a3); UnityEngine.ForceMode a4; checkEnum(l, 5, out a4); self.AddRelativeForce(a1, a2, a3, a4); pushValue(l, true); return(1); } else if (argc == 4) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); System.Single a3; checkType(l, 4, out a3); self.AddRelativeForce(a1, a2, a3); pushValue(l, true); return(1); } else if (argc == 3) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); UnityEngine.ForceMode a2; checkEnum(l, 3, out a2); self.AddRelativeForce(a1, a2); pushValue(l, true); return(1); } else if (argc == 2) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); self.AddRelativeForce(a1); 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)); } }
// Use this for initialization void Start () { // gameController = GameControllerSingleton.get(); rb = GetComponent<Rigidbody>(); rb.AddRelativeTorque(0, initTorque, 0); rb.AddRelativeForce(0, initYForce, 0); initY = transform.position.y; }
// Use this for initialization void Start() { FX = GetComponentInChildren<ParticleSystem> (); destroyTime = Time.time + lifeTime; rb = GetComponent<Rigidbody> (); rb.AddRelativeForce (Vector3.forward * FiredVel, ForceMode.VelocityChange); }
public void getHit(Vector3 hitlocation) { rb = GetComponent<Rigidbody>(); //use this for objects whos HIPS are oriented with Z axis going through them (dick to butt) //rb.AddRelativeForce(new Vector3(0,0,-1) * 3000); //use this for objects whos HIPs are oriented with Y axis going through them (dick to butt) rb.AddRelativeForce(new Vector3(0,-1,0) * 3000); }
void FireNow() { transform.rotation = originalRotation; transform.Rotate (Vector3.forward, Random.Range(-errorX,errorX)); transform.Rotate (Vector3.right, Random.Range(-errorY,errorY)); thisCannonball = Instantiate(cannonball, transform.position, transform.rotation) as Transform; thisRb = thisCannonball.GetComponent<Rigidbody>(); thisRb.AddRelativeForce(Vector3.up * (shootForce + Random.Range(-errorForce,errorForce))); fireNow = false; // resets the button in Unity editor }
static public int AddRelativeForce(IntPtr l) { try{ if (matchType(l, 2, typeof(UnityEngine.Vector3), typeof(UnityEngine.ForceMode))) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); UnityEngine.ForceMode a2; checkEnum(l, 3, out a2); self.AddRelativeForce(a1, a2); return(0); } else if (matchType(l, 2, typeof(UnityEngine.Vector3))) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); UnityEngine.Vector3 a1; checkType(l, 2, out a1); self.AddRelativeForce(a1); return(0); } else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single))) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); System.Single a3; checkType(l, 4, out a3); self.AddRelativeForce(a1, a2, a3); return(0); } else if (matchType(l, 2, typeof(System.Single), typeof(System.Single), typeof(System.Single), typeof(UnityEngine.ForceMode))) { UnityEngine.Rigidbody self = (UnityEngine.Rigidbody)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); System.Single a3; checkType(l, 4, out a3); UnityEngine.ForceMode a4; checkEnum(l, 5, out a4); self.AddRelativeForce(a1, a2, a3, a4); 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); } }
void UpdateJetPack(float force, Rigidbody body, Transform fire) { if (force > 0) body.AddRelativeForce(Vector3.up * 5 * force); if (force == 0) fire.gameObject.GetComponent<MeshRenderer>().enabled = false; else { fire.gameObject.GetComponent<MeshRenderer>().enabled = true; fire.parent.localScale = new Vector3(1, force, 1); } }
static int AddRelativeForce(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); obj.AddRelativeForce(arg0); return(0); } else if (count == 3) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); UnityEngine.Vector3 arg0 = ToLua.ToVector3(L, 2); UnityEngine.ForceMode arg1 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 3, typeof(UnityEngine.ForceMode)); obj.AddRelativeForce(arg0, arg1); return(0); } else if (count == 4) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); float arg1 = (float)LuaDLL.luaL_checknumber(L, 3); float arg2 = (float)LuaDLL.luaL_checknumber(L, 4); obj.AddRelativeForce(arg0, arg1, arg2); return(0); } else if (count == 5) { UnityEngine.Rigidbody obj = (UnityEngine.Rigidbody)ToLua.CheckObject(L, 1, typeof(UnityEngine.Rigidbody)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); float arg1 = (float)LuaDLL.luaL_checknumber(L, 3); float arg2 = (float)LuaDLL.luaL_checknumber(L, 4); UnityEngine.ForceMode arg3 = (UnityEngine.ForceMode)ToLua.CheckObject(L, 5, typeof(UnityEngine.ForceMode)); obj.AddRelativeForce(arg0, arg1, arg2, arg3); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddRelativeForce")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
// Use this for initialization void Start() { myRigidBody = GetComponent<Rigidbody>(); myNetworkView = GetComponent<NetworkView>(); myNetworkManager = Camera.main.GetComponent<NetworkManager>(); myRigidBody.AddRelativeForce(fireForce * Vector3.forward); if (!myNetworkManager.multiplayerEnabled || myNetworkView.isMine) { myTarget = new GameObject("Target"); myTarget.transform.position = Camera.main.GetComponent<ControlsHandler>().mousePosition; myTarget.transform.parent = Camera.main.GetComponent<ControlsHandler>().target; } }
public override void OnFixedUpdate() { if (rigidbody != null) { switch (space) { case Space.World: rigidbody.AddForce(owner.GetValue(force), forceMode); break; case Space.Self: rigidbody.AddRelativeForce(owner.GetValue(force), forceMode); break; } } Finish(); }
//public void AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force); // Use this for initialization void Start() { //public void AddForce(float x, float y, float z, ForceMode mode = ForceMode.Force); rb = GetComponent<Rigidbody>(); rb.AddRelativeForce(x * thrust, y * thrust, z * thrust); }
// Use this for initialization void Start () { rb = GetComponent<Rigidbody>(); rb.AddRelativeForce (Vector3.forward * Force); }
// Use this for initialization void Start () { rb = GetComponent<Rigidbody>(); rb.AddRelativeForce(Vector2.up * force); Destroy(gameObject, lifetime); }
private void jettisonComponent(Rigidbody component, Vector3 forceVector) { component.useGravity = true; component.collider.isTrigger = true; component.constraints = RigidbodyConstraints.None; Vector3 force = transform.InverseTransformDirection(forceVector); force.x = 0; float originalZ = force.z; float zComponent = Random.Range(force.z - 120f, force.z + 120f); force.z = zComponent; component.transform.Rotate(transform.right, (zComponent - originalZ)/2f); component.AddRelativeForce(force, ForceMode.Impulse); barrierComponents.Remove(component); }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody>(); // rb.AddForce(0, 0, speed); rb.AddRelativeForce(0, 0, speed); }
void Start() { rb = GetComponent<Rigidbody>(); rb.AddRelativeForce(Vector3.right * thrust); }
// Use this for initialization void Start() { myRigidBody = GetComponent<Rigidbody>(); myNetworkView = GetComponent<NetworkView>(); myNetworkManager = Camera.main.GetComponent<NetworkManager>(); myRigidBody.maxAngularVelocity = topAngularSpeed; myRigidBody.AddRelativeForce(fireForce * Vector3.forward); myRigidBody.AddRelativeForce(Random.Range(-fireRandomForce, fireRandomForce) * Vector3.right); myRigidBody.AddTorque(Random.Range(-fireRandomTorque, fireRandomTorque) * Vector3.up); transform.Rotate(Vector3.up, Random.Range(-fireRandomAngle, fireRandomAngle)); if (!myNetworkManager.multiplayerEnabled || myNetworkView.isMine) { myTarget = new GameObject("Target"); myTarget.transform.position = Camera.main.GetComponent<ControlsHandler>().mousePosition; myTarget.transform.parent = Camera.main.GetComponent<ControlsHandler>().target; } }
// Use this for initialization void Start() { rb=gameObject.GetComponent<Rigidbody>(); rb.AddRelativeForce(new Vector3(-800, 0, 0)); }