// Use this for initialization void Start() { if (directionRight) { direction = new Vector3(1.0f, 0.0f, 0.0f); offset = new Vector3(1.0f, 1.0f, 0.0f); } else { direction = new Vector3(-1.0f, 0.0f, 0.0f); offset = new Vector3(-2.0f, 1.0f, 0.0f); } if (!directionRight) { SpriteRenderer spriterenderer = gameObject.GetComponent<SpriteRenderer>(); Vector3 scale = spriterenderer.transform.localScale; scale.x *= -1; spriterenderer.transform.localScale = scale; } gameObject.transform.position = player.gameObject.transform.position + offset; rigidBody = GetComponent<Rigidbody>(); rigidBody.AddForce(direction * thrust, ForceMode.Impulse); }
// Update is called once per frame void Update() { hero = GetComponent<Rigidbody> (); anim.SetBool("is_jump", !grounded); if (grounded && ((Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.Space)))) { hero.AddForce(new Vector3(0f, ForceJump, 0f)); //soundJump.Play(); } hero.velocity = new Vector3(move * MaxSpeed, hero.velocity.y, hero.velocity.z); if (move == 0) { anim.SetBool ("boolrun", false); }else { anim.SetBool("boolrun", true); } if (Input.GetKey (KeyCode.R)) { Application.LoadLevel(Application.loadedLevel); } if (facingRight && move < 0) { Flip(); } else if(!facingRight && move > 0) { Flip(); } }
// Use this for initialization void Start() { myRigidbody = GetComponent<Rigidbody>(); int toss = Random.Range (1,3); switch(toss){ case 1: myRigidbody.AddForce (-Vector3.right * 50, ForceMode.Impulse); break; case 2: myRigidbody.AddForce (Vector3.right * 50, ForceMode.Impulse); break; } }
// Use this for initialization void Start() { S = this; rb = GetComponent<Rigidbody>(); rb.AddForce(Vector3.forward * 20); rb.AddForce(Vector3.up * 10); mouseXPos = 0; }
public static void jump(Rigidbody player, Vector3 force) { if (GameManager.Instance.ThePlayer.GetComponent<PlayerProperties>().CheckGroundDist()) { player.AddForce(force); } }
public void applyLinearForce(Rigidbody toBody, Vector3 desiredForce, bool relative) { if(relative) toBody.AddRelativeForce (desiredForce, this.forceMode); else toBody.AddForce (desiredForce, this.forceMode); }
void Start() { bullet = this.GetComponent<Rigidbody>(); bullet.AddForce(this.transform.forward * thrust); GameObject.Destroy(this.gameObject, 3.0f); }
void FixedUpdate() { // Forward rb.AddForce(0, 0, forwardForce * Time.deltaTime); // Steer left if (Input.GetKey("a") || Input.GetKey(KeyCode.LeftArrow)) { rb.AddForce(-sidewardForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } // Steer right if (Input.GetKey("d") || Input.GetKey(KeyCode.RightArrow)) { rb.AddForce(sidewardForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange); } // Boost if (useBoost && boostReserve > 0f && (Input.GetKey("w") || Input.GetKey(KeyCode.UpArrow)) && (boostReserve > boostAcivationThreshold || boostActive)) { boostActive = true; rb.AddForce(0, 0, boostForce * Time.deltaTime, ForceMode.VelocityChange); // Reduce boost on usage boostReserve -= boostConsume * Time.deltaTime; // Make sure boost reserve is never negative if (boostReserve <= 0f) { boostReserve = 0f; boostActive = false; } } else { boostActive = false; } // Recharge boost if (boostReserve <= boostReserveMax) { boostReserve += boostRecharge * Time.deltaTime; } // Jump if (Input.GetKey(KeyCode.Space)) { if (IsGrounded()) { rb.AddForce(0, jumpImpulse, 0, ForceMode.Impulse); } } // "Die" if (rb.position.y < -3f) { FindObjectOfType <GameManager>().EndGame(); } }
void Start() { rigidbody = GetComponent<Rigidbody>(); if(Application.loadedLevel == 2) rigidbody.AddForce(800000000, 0, 0); else rigidbody.AddForce(71000, 0, 0); }
void Start() { sounds = GetComponents<AudioSource>(); quack = sounds[0]; rb = GetComponent<Rigidbody>(); rb.AddForce(transform.forward * speed); rb.AddForce(transform.up * speed2); }
void Awake() { //reference to rigidbody and transform for force appplication rigidbody = GetComponent<Rigidbody>(); orbital = this.transform; //starting force rigidbody.AddForce(Vector3.left * speed); rigidbody.AddForce(Vector3.up * speed); }
void OnCollisionEnter(Collision col) { rb = GetComponent<Rigidbody>(); if (col.gameObject.name.Contains("shield")) { rb.AddForce(col.gameObject.transform.forward * BounceStrength * -1); } else { rb.AddForce(col.gameObject.transform.forward * BounceStrength); } }
// Use this for initialization void Start() { //bullets set to disappear after thirty seconds, rotate for prefab weirdness initialForce = 300; Destroy(this.gameObject, 30); transform.Rotate(90,0,0); //initial force only body = GetComponent<Rigidbody>(); body.constraints = RigidbodyConstraints.FreezeRotationY; body.AddForce(transform.right * Random.Range(-deviation,deviation)); body.AddForce(transform.up * initialForce); }
void Update() { int layerMask = 1 << 8; layerMask = ~layerMask; RaycastHit hit; if (Physics.Raycast(this.gameObject.transform.Find("ray").gameObject.transform.position, raydir, out hit, 0.2f)) { if (Input.GetKey(jumpKey)) { rb.AddForce(vecJump); } } if (Input.GetKey(downKey)) { rb.AddForce(-vecJump); } if (Input.GetKey(fowardKey)) { this.gameObject.transform.eulerAngles = new Vector3(0, 0, 0); left = false; rb.AddForce(vecForward); } if (Input.GetKey(backKey)) { this.gameObject.transform.eulerAngles = new Vector3(0, 180, 0); left = true; rb.AddForce(-vecForward); } if (Input.GetKeyDown(shootKey)) { // Vector3 gunpos = gun.transform.position; var shot = Instantiate(projectile, gun.transform.position, gun.transform.rotation); if (left) { shot.GetComponent <Rigidbody>().AddForce(-shootforce); } else { shot.GetComponent <Rigidbody>().AddForce(shootforce); } } }
// Use this for initialization void Start() { move = GetComponent<Rigidbody> (); hitmarker = GetComponent<AudioSource> (); gameObject.GetComponent<SpawnPongBall> (); move.AddForce (Vector3.forward * speed); }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody> (); rb.AddForce (transform.forward * speed); // 弾丸が作成された位置がFirePosの位置と同じ firePos = transform.position; }
// Update is called once per frame void FixedUpdate() { if (Input.GetKeyUp(KeyCode.Space)) { if (!(jammersThrown == TotalJammers)) { jammersThrown++; GameObject Clone = Instantiate(JammerGameObject); Clone.transform.position = JammerOrigin.position; jammerPhysics = Clone.GetComponent<Rigidbody>(); jammerPhysics.useGravity = true; jammerPhysics.isKinematic = false; jammerPhysics.AddForce(transform.forward * 100); } } }
// Use this for initialization void Update() { if(Input.GetMouseButtonDown(0) && ammo.current >= 1) { GameObject temp = Instantiate(starPrefab); temp.transform.position = trans.TransformPoint(Vector3.right*1f); temp.transform.rotation.SetLookRotation(temp.transform.TransformPoint(Vector3.forward)); starRB = temp.GetComponent<Rigidbody>(); starRB.useGravity = false; starRB.AddForce(trans.forward*(1000f +(100f*Input.GetAxis("Vertical")))); starRB.AddForce(trans.TransformDirection(Vector3.left)*100f); starRB.gameObject.GetComponentInParent<Transform>().rotation = Quaternion.LookRotation(trans.forward); Destroy(temp, 3f); ammo.SpendAmmo(1); } }
void TouchShoot() { touch = Input.GetTouch (0); //Raycast to find out where the cannonball should be fired towards RaycastHit shothit; //Finding mouse position when left mouse button is pressed shot = touch.position; //Translating screen position of mouse to world position on the field. Ray mouseClick = Camera.main.ScreenPointToRay(shot); //Final vector for firing cannonball Vector3 shotdirection; //If the click actually lands on the field it will fire the cannonball if (Physics.Raycast(mouseClick, out shothit, Mathf.Infinity, layerMask)) { if (shothit.collider.CompareTag ("Surface") || shothit.collider.CompareTag ("Surface")) { //Creating cannonball in front of cannon barrel reload = Instantiate(cannonball, shotorigin.position, shotorigin.rotation) as Rigidbody; //Calculating final shot vector by taking position of mouse and subtracting position of cannon shotdirection = shothit.point - reload.transform.position; shotdirection.Normalize (); //Applying force to cannonball along the vector reload.AddForce(shotdirection * shotspeed); //Play cannon animation GetComponent<Animation>().Play("Cannon_Fire"); } } }
// Use this for initialization void Start() { _bounceBack = GetComponent<BounceBack> (); _rb = GetComponent<Rigidbody> (); _rb.AddForce( transform.right * 500 ); }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody>(); m_speed.x = speed * Random.Range(-2, 2); m_speed.y = speed * Random.Range(-2, 2); rb.AddForce(m_speed.x , 0, m_speed.y); }
// Use this for initialization void Start () { rb = GetComponent<Rigidbody>(); t = GetComponent<Transform>(); rb.AddForce(Vector3.forward * force); }
// Use this for initialization void Start() { myPv = this.gameObject.GetComponent<PhotonView>(); myCollider = GetComponent<BoxCollider>(); rb = this.gameObject.GetComponent<Rigidbody>(); rb.AddForce(transform.forward * projectileSpeed); }
void shootAt(GameObject obj) { bullet = Instantiate (bulletPrefab, transform.position + Vector3.up, Quaternion.identity) as Rigidbody; BulletScript bulletScript = (BulletScript)bullet.GetComponent (typeof(BulletScript)); bulletScript.damage = 10; bullet.AddForce (BallisticVel (obj.transform), ForceMode.Impulse); }
private IEnumerator pullObject(Rigidbody collidedRigidbody) { while(Vector3.Distance(transform.parent.position, collidedRigidbody.transform.position) > 1.5f) { pullTimer -= Time.deltaTime; if(pullTimer < 0) { yield return new WaitForSeconds(0.333f); pullTimer = resetPullTimer; } else { collidedRigidbody.MovePosition(collidedRigidbody.transform.position + Vector3.up * pullSpeed * Time.deltaTime); yield return null; } } //reach top now make fall if (collidedRigidbody.gameObject.tag != "Player") { collidedRigidbody.AddForce(Vector3.right * 10, ForceMode.Impulse); } // else // { // //atTop = true; // } }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody> (); rb.AddForce ((Vector3.up * upVelocity) + (Vector3.left * Random.Range (-pushAmt, pushAmt)) + (Vector3.forward * Random.Range (-pushAmt, pushAmt))); rb.AddTorque (Vector3.up * Random.Range (-turnAmt, turnAmt)); rb.AddTorque (Vector3.left * Random.Range (-turnAmt, turnAmt)); }
public bool handleCollision(ControllerColliderHit hit, Rigidbody body, float force) { Vector3 pushDir = new Vector3 (hit.moveDirection.x, 0, hit.moveDirection.z); // body.velocity = pushDir * force; body.AddForce (pushDir * force); return false; }
static public int AddForce(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.AddForce(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.AddForce(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.AddForce(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.AddForce(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() { m_Rigidbody = GetComponent<Rigidbody>(); m_Rigidbody.AddForce(transform.right * m_Force); Destroy(gameObject, m_LifeTime); }
void pressedShot() { // Remove Listener btnShoot.onClick.RemoveAllListeners(); // Push Sign back float PushPower = Random.Range (100,200); rigidBody = transform.gameObject.AddComponent<Rigidbody> (); rigidBody.AddForce (new Vector3(-PushPower, 0, PushPower)); // Play Smack Sound int soundNum = Random.Range (0,3); if(soundNum == 0) GetComponent<SoundsTriggered>().playSound1(true, 1); else if (soundNum == 1) GetComponent<SoundsTriggered>().playSound2(true, 1); else if (soundNum == 2) GetComponent<SoundsTriggered>().playSound3(true, 1); // Flag CollisionAble isReadyToCollide = true; // Flag animation to play and do a-da Jump'a isReadyToJump = true; // Hide Indicator DirectionIndicator.SetActive (false); }
public void StartMe(float lifetime, bool blackColor) { this.blackColor = blackColor; exploteIn = Time.time + lifetime; rigidbody = GetComponent<Rigidbody>(); rigidbody.AddForce(transform.forward * speed); }
// Use this for initialization void Start() { rb = GetComponent<Rigidbody>(); rb.AddForce(transform.right * MovementSpeed * -100.0f); rb.angularVelocity = Random.insideUnitSphere * tumble; }
// Use this for initialization void Start() { if (!isServer) this.enabled = false; rb = GetComponent<Rigidbody>(); rb.AddForce(transform.forward * impulseThrust, ForceMode.Impulse); }
public static void AddForce(UnityEngine.Rigidbody rigidbody, Vector3 force, ForceMode forceMode) { if (force == Vector3.zero) { return; } rigidbody.AddForce(force * Time.fixedDeltaTime, forceMode); }
static public int AddForce(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.AddForce(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.AddForce(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.AddForce(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.AddForce(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 Update() { if (Input.GetKeyDown(jumpKey)) { Debug.Log("Jump taste wurde gedrückt"); rb.AddForce(vecJump); } if (Input.GetKeyDown(downKey)) { Debug.Log("Jump taste wurde gedrückt"); rb.AddForce(-vecJump); } if (Input.GetKeyDown(fowardKey)) { Debug.Log("Forwärts taste wurde gedrückt"); rb.AddForce(vecForward); } if (Input.GetKeyDown(backKey)) { Debug.Log("Zurück taste wurde gedrückt"); rb.AddForce(-vecForward); } if (Input.GetKeyDown(shootKey)) { s { // Vector3 gunpos = gun.transform.position; GameObject forcegun = Instantiate(projectile, gun.transform.position, gun.transform.rotation); Rigidbody rb = forcegun.GetComponent <Rigidbody>(); rb.AddForce(af); //Instantiate(projectile, gun.transform.position, gun.transform.rotation); } } }
static int AddForce(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.AddForce(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.AddForce(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.AddForce(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.AddForce(arg0, arg1, arg2, arg3); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.Rigidbody.AddForce")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected virtual void DoMovement(Vector3 position) { Vector3 dir = position - owner.transform.position; dir.y = -gravity; rigidbody.AddForce(owner.transform.forward * speed, ForceMode.VelocityChange); dir.y = 0; if (dir != Vector3.zero && dir.sqrMagnitude > 0) { desiredRotation = Quaternion.LookRotation(dir, Vector3.up); } lastRotation = Quaternion.Slerp(lastRotation, desiredRotation, rotation * Time.deltaTime); owner.transform.rotation = lastRotation; }
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(); }
void FixedUpdate() {//all physics calculations are done here //Get whether the arrow keys have been pressed float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical");//vertical actually means in the z direction //Move the ball in the direction of those keys Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); //Second param is 0 cuz the ball is only moving from side to side //Apply the force - ball will now move as though it were 'pushed' _rigidbody.AddForce(movement * speed * Time.deltaTime); //remember to adjust ball speed by delta time, //or it will run at different speeds on different machines //depending on the machine's frame rate }
public void FixedUpdate() { // Wait until the ragdoll is at rest before recording positions if (Time.time > InitDelay && !IsInitialized) { init(); } if (IsInitialized) { var diff = DesiredPosition - (transform.position + _rigidbody.velocity * LeadTime); var dist = new Vector3(Mathf.Abs(diff.x), Mathf.Abs(diff.y), Mathf.Abs(diff.z)); var pullM = new Vector3(Mathf.Clamp01(dist.x / 0.3f), Mathf.Clamp01(dist.y / 0.3f), Mathf.Clamp01(dist.z / 0.3f)); var force = new Vector3(Mathf.Sign(diff.x) * PullForce * pullM.x * Time.deltaTime, Mathf.Sign(diff.y) * PullForce * pullM.y * Time.deltaTime, Mathf.Sign(diff.z) * PullForce * pullM.z * Time.deltaTime); _rigidbody.AddForce(force, ForceMode.Impulse); } }