public void AddRelativeForce(ForceDirection forceDirection) { Vector2 forceDirectionVector = Vector2.zero; switch (forceDirection) { case ForceDirection.Up: forceDirectionVector = Vector2.up; break; case ForceDirection.Down: forceDirectionVector = Vector2.down; break; default: Debug.Assert(false, "Unprocessed force direction case!"); break; } playerRigidbody2D.AddRelativeForce(mainForce * Time.deltaTime * forceDirectionVector); if (Mathf.Abs(playerRigidbody2D.velocity.x) > maxAxisVelocity) { float newVelocity = (playerRigidbody2D.velocity.x > 0) ? maxAxisVelocity : -1 * maxAxisVelocity; playerRigidbody2D.velocity = new Vector2(newVelocity, playerRigidbody2D.velocity.y); } if (Mathf.Abs(playerRigidbody2D.velocity.y) > maxAxisVelocity) { float newVelocity = (playerRigidbody2D.velocity.y > 0) ? maxAxisVelocity : -1 * maxAxisVelocity; playerRigidbody2D.velocity = new Vector2(playerRigidbody2D.velocity.x, newVelocity); } }
public AddForceNode(Rigidbody rigidbody, Transform obj, ForceDirection forceDirection, float magnitude, ForceMode forceMode) { this.rb = rigidbody; this.obj = obj; this.magn = magnitude; this.fM = forceMode; this.forceDirection = forceDirection; }
/// <summary> /// Updates the player's velocity by adding force in the specified direction. /// Should be called once per frame any time a directional key is held down /// </summary> public void updateVelocity(ForceDirection direction) { switch (direction) { case ForceDirection.Up: yVel += UPDATE_FORCE_Y; if (yVel > MAX_VEL) { yVel = MAX_VEL; } if (yVel < -MAX_VEL) { yVel = -MAX_VEL; } break; case ForceDirection.Down: yVel -= UPDATE_FORCE_Y; if (yVel > MAX_VEL) { yVel = MAX_VEL; } if (yVel < -MAX_VEL) { yVel = -MAX_VEL; } break; case ForceDirection.Right: xVel += UPDATE_FORCE_X; if (xVel > MAX_VEL) { xVel = MAX_VEL; } if (xVel < -MAX_VEL) { xVel = -MAX_VEL; } break; case ForceDirection.Left: xVel -= UPDATE_FORCE_X; if (xVel > MAX_VEL) { xVel = MAX_VEL; } if (xVel < -MAX_VEL) { xVel = -MAX_VEL; } break; } }
public static Vector3 GetDirection(ForceDirection dir, Transform forceOrigin, Transform forceTarget) { switch (dir) { case ForceDirection.Relative: return (forceTarget.position - forceOrigin.position).normalized; case ForceDirection.Random: return RandomUtil.Standard.OnUnitSphere(); case ForceDirection.Forward: return forceOrigin.forward; } return Vector3.zero; }
public static Vector3 GetDirection(ForceDirection dir, Trans forceOrigin, Trans forceTarget) { switch (dir) { case ForceDirection.Relative: return((forceTarget.Position - forceOrigin.Position).normalized); case ForceDirection.Random: return(RandomUtil.Standard.OnUnitSphere()); case ForceDirection.Forward: return(forceOrigin.Forward); } return(Vector3.zero); }
public static Vector2 GetDirection(IPlanarSurface surface, ForceDirection dir, Trans forceOrigin, Trans forceTarget) { if (surface == null) { return(Vector2.zero); } switch (dir) { case ForceDirection.Relative: return(surface.ProjectVectorTo2D(forceOrigin.Position, (forceTarget.Position - forceOrigin.Position)).normalized); case ForceDirection.Random: return(RandomUtil.Standard.OnUnitCircle()); case ForceDirection.Forward: return(surface.ProjectVectorTo2D(forceOrigin.Position, forceOrigin.Forward).normalized); } return(Vector2.zero); }
/// <summary> /// Applies forces the velocity /// </summary> /// <param name="dir"> /// direction /// </param> /// <param name="power"> /// the force/power added to the velocity in that direction /// </param> public void ApplyForce(ForceDirection dir, float power) { switch (dir) { case ForceDirection.Up: Velocity += new Vec2F(0, power); break; case ForceDirection.Down: Velocity += new Vec2F(0, -power); break; case ForceDirection.Left: Velocity += new Vec2F(-power, 0); break; case ForceDirection.Right: Velocity += new Vec2F(power, 0); break; } }
public ConfigurableForce(float strength, ForceMode mode, ForceDirection dir) { _direction = dir; _strength = strength; _forceMode = mode; }
public static Vector2 GetDirection(IPlanarSurface surface, ForceDirection dir, Trans forceOrigin, Trans forceTarget) { if (surface == null) return Vector2.zero; switch (dir) { case ForceDirection.Relative: return surface.ProjectVectorTo2D(forceOrigin.Position, (forceTarget.Position - forceOrigin.Position)).normalized; case ForceDirection.Random: return RandomUtil.Standard.OnUnitCircle(); case ForceDirection.Forward: return surface.ProjectVectorTo2D(forceOrigin.Position, forceOrigin.Forward).normalized; } return Vector2.zero; }