//--Shoot implementation private void performShootFromPoint(GameObject inShootingPoint) { Vector2 thePointWorld = new Vector2(); float theRotation = 0.0f; XMath.getFromTransform( ref thePointWorld, ref theRotation, inShootingPoint ); Vector2 theDiraction = XMath.getDiractionVectorForAngle(theRotation); float theShootingDistance = 10.0f; RaycastHit2D[] theHits = Physics2D.RaycastAll( thePointWorld, theDiraction, theShootingDistance ); Vector2 theHitPoint = new Vector2(); Vector2 theHitNormal = new Vector2(); Collider2D theHittedCollider = null; foreach (RaycastHit2D theHit in theHits) { if (shouldIgnoreColliderOnHit(theHit.collider)) { continue; } theHittedCollider = theHit.collider; theHitPoint = theHit.point; theHitNormal = theHit.normal; break; } notifyEffectsAboutShoot(thePointWorld, theDiraction, theShootingDistance, theHitPoint, !!theHittedCollider ); if (!theHittedCollider) { return; } Rigidbody2D theShootedRigidBody = theHittedCollider.gameObject.GetComponent <Rigidbody2D>(); if (!theShootedRigidBody) { return; } float theForce = 30.0f; theShootedRigidBody.AddForceAtPosition(theDiraction * theForce, theHitPoint); var theDurability = theShootedRigidBody.gameObject.GetComponent <DurabilityComponent>(); if (theDurability) { theDurability.changeHitPoints(-5.0f); } }
private Vector2 getWheelResistanceForce(WheelState inWheelState) { Vector2 theWheelPosition = getWheelWorldPosition(inWheelState); float theWheelsRotation = getWheelWorldRotation(inWheelState); Vector2 theVelocityInWheelPosition = _rigidBody.GetPointVelocity(theWheelPosition); Vector3 theWheelsDiraction = XMath.getDiractionVectorForAngle(theWheelsRotation); Vector2 theDirectProjectedAccumulateVelocity = Vector3.Project(theVelocityInWheelPosition, theWheelsDiraction); Vector2 theDirectResistanceForce = -theDirectProjectedAccumulateVelocity * _directResistanceK; Vector3 theWheelsNormalDiraction = XMath.getVectorRotatedBy90Degrees(theWheelsDiraction); Vector2 theSideProjectedAccumulateVelocity = Vector3.Project(theVelocityInWheelPosition, theWheelsNormalDiraction); Vector2 theSideResistanceForce = -theSideProjectedAccumulateVelocity * _sideResistanceK; return(theDirectResistanceForce + theSideResistanceForce); }
private Vector2 calculateVelocityDiraction() { float theRotation = transform.rotation.eulerAngles.z; return(XMath.getDiractionVectorForAngle(theRotation)); }
private Vector2 getWheelGasForce(WheelState inWheelState, float inGasValue) { Vector2 theDiraction = XMath.getDiractionVectorForAngle(getWheelWorldRotation(inWheelState)); return(theDiraction * inGasValue); }