public void TickCollisions(TickCollisionsEvent _) { // TODO: Do this via collision detection instead. // TODO: Clean this up. // Keeps sword rested on the ground. if (this.stateMachine_.IsOnGround) { var bladeFromGroundY = -(this.playerRigidbody_.CenterY - this.playerRigidbody_.BottomY); bladeFromGroundY -= MathF.Abs( TrigMath.LenDegY(this.handDis_, this.handDeg_)); var minAngle = MathF.Acos(bladeFromGroundY / this.bladeLength_) / MathF.PI * 180; var diffToGround = TrigMath.DifferenceInDegrees(this.swordDeg_, 270); if (FloatMath.Abs(diffToGround) <= minAngle) { this.swordDeg_ = 270 + FloatMath.Sign(diffToGround) * minAngle; if (FloatMath.Abs(this.swordDevVel_) > 2) { this.swordDevVel_ *= -.5f; } else { this.swordDevVel_ = 0; } } } }
public void ProcessInputs(ProcessInputsEvent _) { var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY]; var secStickX = secondaryAnalogStick.RawAxes.X; var secStickY = secondaryAnalogStick.RawAxes.Y; var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY); if (secStickMag < GamepadConstants.DEADZONE) { secStickMag = 0; } var wasShieldOut = this.isShieldOut_; this.isShieldOut_ = secStickMag > 0; if (this.isShieldOut_) { var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY); var toHandDeg = secStickDeg; var maxHorizontalHandDis = this.playerRigidbody_.Width / 2 + 2; var maxVerticalHandDis = this.playerRigidbody_.Height / 2 + 2; var maxHandDis = FloatMath.Abs( TrigMath.LenDegX(maxHorizontalHandDis, secStickDeg)) + FloatMath.Abs( TrigMath.LenDegY(maxVerticalHandDis, secStickDeg)); var toHandDis = maxHandDis * secStickMag; if (!wasShieldOut) { this.handDis_ = toHandDis; this.handDeg_ = toHandDeg; } else { var accFactor = 3; this.handDis_ += (toHandDis - this.handDis_) / accFactor; this.handDeg_ += TrigMath.DifferenceInDegrees(toHandDeg, this.handDeg_) / accFactor; } } }
private void ProcessManualInputs_() { var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY]; var secStickX = secondaryAnalogStick.RawAxes.X; var secStickY = secondaryAnalogStick.RawAxes.Y; var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY); if (secStickMag < GamepadConstants.DEADZONE) { secStickMag = 0; } var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY); var isResting = secStickMag == 0; // TODO: Detect arcs? /*if (isResting) { * var xVel = this.playerRigidbody_.XVelocity; * if (xVel != 0) { * var sign = FloatMath.Sign(xVel); * * this.handDis_ = this.maxHandDis_; * * if (this.stateMachine_.State == PlayerState.WALKING) { * this.handDeg_ = 90 - sign * (90 + 45); * this.swordDeg_ = 90 - sign * 45; * } else if (this.stateMachine_.State == PlayerState.RUNNING) { * this.handDeg_ = 90 + sign * (90 + 22); * this.swordDeg_ = 90 + sign * (90 + 22); * } * } * return; * }*/ // Stick moves hands to lift sword. Angle needs to be closer to have // more of an effect. var diffToHeld = TrigMath.DifferenceInDegrees(secStickDeg, this.handDeg_); var normalizedDiffToHeld = MathF.Abs(diffToHeld / 180); var moveFactor = 1 - normalizedDiffToHeld; var diffToTop = TrigMath.DifferenceInDegrees(90, this.handDeg_); var isLifting = FloatMath.Sign(diffToTop) == FloatMath.Sign(diffToHeld); var moveForce = 0f; var liftFactor = secStickMag * MathF.Pow(moveFactor, 5); // 4, 6, 7 if (isLifting) { var liftForce = .6f * diffToHeld * liftFactor; // .5f moveForce = liftForce; } else { var dropFactor = secStickMag; var dropForce = .8f * diffToHeld * dropFactor; moveForce = dropForce; } var initDiffToGround = TrigMath.DifferenceInDegrees(270, this.handDeg_); var gravitationalForce = 3 * FloatMath.Sign(initDiffToGround); var forceOnHands = moveForce + gravitationalForce; // TODO: Use euler method? this.handDegVel_ += forceOnHands; this.handDeg_ += this.handDegVel_; var minAngle = 45; var finalDiffToGround = TrigMath.DifferenceInDegrees(this.handDeg_, 270); if (FloatMath.Abs(finalDiffToGround) < minAngle) { this.handDeg_ = 270 + FloatMath.Sign(finalDiffToGround) * minAngle; if (FloatMath.Abs(this.handDegVel_) > 2) { this.handDegVel_ *= -.5f; } else { this.handDegVel_ = 0; } } // TODO: This line should theoretically not be here?? //this.handDeg_ += diffToHeld * liftFactor; this.handDeg_ %= 360; // TODO: Keep this value when the player lets go of the stick this.handDis_ = 16 * secStickMag; // TODO: Should be based on velocity instead. // If lifting sword, sword angle lags behind. //this.swordDeg_ = this.handDeg_; var swordDegAccFac = 1 / (1 + MathF.Abs(this.handDegVel_)); this.swordDeg_ += TrigMath.DifferenceInDegrees(this.handDeg_, this.swordDeg_) * swordDegAccFac; }