gg.easy.airship 0.1.1821 → 0.1.1823

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- using UnityEngine;
1
+ using UnityEditor.EditorTools;
2
+ using UnityEngine;
2
3
  using UnityEngine.Serialization;
3
4
 
4
5
  namespace Code.Player.Character.API {
@@ -28,6 +29,9 @@ namespace Code.Player.Character.API {
28
29
  public float accelerationForce = 1;
29
30
  [Tooltip("How much to accelerate sprinting (units per second) when using acceleration movement or when going faster than the target speed")] [Min(0f)]
30
31
  public float sprintAccelerationForce = 1.4f;
32
+ [Tooltip("If accelerating in a direction you are already moving, how much force can you still apply?")]
33
+ [Range(0,1)]
34
+ public float minAccelerationDelta = 0;
31
35
 
32
36
  [Tooltip("Only allow sprinting forward.")]
33
37
  public bool onlySprintForward = false;
@@ -40,6 +40,7 @@ namespace Code.Player.Character {
40
40
  private Vector2 targetVelNormalized;
41
41
  private float verticalVel = 0;
42
42
  private float currentPlaybackSpeed = 0;
43
+ private float currentSpeed = 0;
43
44
  private bool firstPerson = false;
44
45
  private float lastStateTime = 0;
45
46
  private float targetPlaybackSpeed = 0;
@@ -131,9 +132,9 @@ namespace Code.Player.Character {
131
132
  //Blend directional influence
132
133
  float blendMod = targetMagnitude > currentMagnitude ? this.directionalBlendLerpMod : this.directionalBlendLerpMod /2f;
133
134
  currentVelNormalized = Vector2.MoveTowards(currentVelNormalized, targetVelNormalized, blendMod * Time.deltaTime);
134
- animator.SetFloat("VelX", Mathf.Abs(currentVelNormalized.x) < .01 ? 0 : currentVelNormalized.x);// * Mathf.Clamp01(currentPlaybackSpeed));
135
+ animator.SetFloat("VelX", currentSpeed < .01 ? 0 : currentVelNormalized.x);// * Mathf.Clamp01(currentPlaybackSpeed));
135
136
  animator.SetFloat("VelY", Mathf.Lerp(animator.GetFloat("VelY"), verticalVel, Time.deltaTime*1.5f));
136
- animator.SetFloat("VelZ", Mathf.Abs(currentVelNormalized.y) < .01 ? 0 : currentVelNormalized.y);// * Mathf.Clamp01(currentPlaybackSpeed));
137
+ animator.SetFloat("VelZ", currentSpeed < .01 ? 0 : currentVelNormalized.y);// * Mathf.Clamp01(currentPlaybackSpeed));
137
138
  animator.SetFloat("Speed", targetMagnitude);
138
139
 
139
140
 
@@ -166,7 +167,7 @@ namespace Code.Player.Character {
166
167
  } else if (currentState == CharacterState.Crouching) {
167
168
  targetSpeed = 2.1233335f;
168
169
  }
169
- var currentSpeed = new Vector2(localVel.x, localVel.z).magnitude;
170
+ currentSpeed = new Vector2(localVel.x, localVel.z).magnitude;
170
171
  //print("currentSpeed: " + currentSpeed + " targetSpeed: " + targetSpeed + " playbackSpeed: " + targetPlaybackSpeed);
171
172
  this.targetPlaybackSpeed = Mathf.Max(0, currentSpeed / targetSpeed);
172
173
  targetVelNormalized = new Vector2(localVel.x, localVel.z).normalized;
@@ -287,7 +287,6 @@ private void OnEnable() {
287
287
  if (grounded && !prevGrounded) {
288
288
  jumpCount = 0;
289
289
  timeSinceBecameGrounded = 0f;
290
- airborneFromImpulse = false;
291
290
  this.OnImpactWithGround?.Invoke(currentVelocity);
292
291
  } else {
293
292
  timeSinceBecameGrounded = Math.Min(timeSinceBecameGrounded + deltaTime, 100f);
@@ -560,8 +559,9 @@ private void OnEnable() {
560
559
 
561
560
  //Apply the impulse to the velocity
562
561
  newVelocity += impulseVelocity;
562
+ airborneFromImpulse = !grounded || impulseVelocity.y > .01f;
563
+ print("gounded: " + grounded + " impulseVelocity: " + impulseVelocity);
563
564
  impulseVelocity = Vector3.zero;
564
- airborneFromImpulse = true;
565
565
  }
566
566
  #endregion
567
567
 
@@ -674,35 +674,20 @@ private void OnEnable() {
674
674
  //Instantly move at the desired speed
675
675
  var moveMagnitude = characterMoveVelocity.magnitude;
676
676
  var velMagnitude = flatVelocity.magnitude;
677
- //var clampedIncrease = normalizedMoveDir * Mathf.Min(moveMagnitude, Mathf.Max(0, currentSpeed - velMagnitude));
678
-
679
677
 
680
678
  //Don't move character in direction its already moveing
681
679
  //Positive dot means we are already moving in this direction. Negative dot means we are moving opposite of velocity.
682
- //var rawDot = Vector3.Dot(flatVelocity/ currentSpeed, characterMoveVelocity/ currentSpeed);
680
+ //Multipy by 2 so perpendicular movement is still fully applied rather than half applied
683
681
  var rawDot = Vector3.Dot(flatVelocity.normalized, normalizedMoveDir);
684
- var dirDot = Mathf.Clamp01(1-rawDot);
682
+ var dirDot = Mathf.Max(moveData.minAccelerationDelta, Mathf.Clamp01((1-rawDot)*2));
685
683
 
686
684
  if(useExtraLogging){
687
685
  print("old vel: " + currentVelocity + " new vel: " + newVelocity + " move dir: " + characterMoveVelocity + " Dir dot: " + dirDot + " currentSpeed: " + currentSpeed + " grounded: " + grounded + " canJump: " + canJump + " didJump: " + didJump);
688
686
  }
689
-
690
- if (inAir){
691
- //clampedIncrease *= moveData.airSpeedMultiplier;
692
- }
693
-
694
- if(_flying || (velMagnitude < (moveData.useAccelerationMovement?currentSpeed:Mathf.Max(moveData.sprintSpeed, currentSpeed) + 1) && !isImpulsing)){
695
- // if(clampedIncrease.x < 0){
696
- // clampedIncrease.x = Mathf.Max(clampedIncrease.x, newVelocity.x + clampedIncrease.x);
697
- // }else{
698
- // clampedIncrease.x = Mathf.Min(clampedIncrease.x, newVelocity.x + clampedIncrease.x);
699
- // }
700
- // if(clampedIncrease.z < 0){
701
- // clampedIncrease.z = Mathf.Max(clampedIncrease.z, newVelocity.z + clampedIncrease.z);
702
- // }else{
703
- // clampedIncrease.z = Mathf.Min(clampedIncrease.z, newVelocity.z + clampedIncrease.z);
704
- // }
705
-
687
+ print("airborneFromImpulse: " + airborneFromImpulse);
688
+ if(_flying || //In Fly mode OR
689
+ (!isImpulsing && !airborneFromImpulse && //Not impulsing AND under our max speed
690
+ (velMagnitude < (moveData.useAccelerationMovement?currentSpeed:Mathf.Max(moveData.sprintSpeed, currentSpeed) + 1)))){
706
691
  if(moveData.useAccelerationMovement){
707
692
  newVelocity += characterMoveVelocity;
708
693
  }else{
@@ -710,21 +695,10 @@ private void OnEnable() {
710
695
  newVelocity.z = characterMoveVelocity.z;
711
696
  }
712
697
  }else{
713
- //dirDot = dirDot - 1 / 2;
714
- //clampedIncrease *= -Mathf.Min(0, dirDot-1);
698
+ //Moving faster than max speed or using acceleration mode
715
699
  newVelocity += normalizedMoveDir * (dirDot * dirDot / 2) *
716
700
  (groundedState == CharacterState.Sprinting ? this.moveData.sprintAccelerationForce : moveData.accelerationForce);
717
701
  }
718
- //characterMoveVelocity = clampedIncrease;
719
- // if(Mathf.Abs(newVelocity.x) < Mathf.Abs(characterMoveVelocity.x)){
720
- // newVelocity.x = characterMoveVelocity.x;
721
- // }
722
- // if(Mathf.Abs(newVelocity.y) < Mathf.Abs(characterMoveVelocity.y)){
723
- // newVelocity.y = characterMoveVelocity.y;
724
- // }
725
- // if(Mathf.Abs(newVelocity.z) < Mathf.Abs(characterMoveVelocity.z)){
726
- // newVelocity.z = characterMoveVelocity.z;
727
- // }
728
702
 
729
703
  //print("isreplay: " + replaying + " didHitForward: " + didHitForward + " moveVec: " + characterMoveVector + " colliderDot: " + colliderDot + " for: " + forwardHit.collider?.gameObject.name + " point: " + forwardHit.point);
730
704
  #endregion
@@ -769,8 +743,10 @@ private void OnEnable() {
769
743
  var canStopVel = !airborneFromImpulse && (!inAir || moveData.useMinimumVelocityInAir) && !isImpulsing;
770
744
  var notTryingToMove = normalizedMoveDir.sqrMagnitude < .1f;
771
745
  var underMin = physics.GetFlatDistance(Vector3.zero, newVelocity) <= moveData.minimumVelocity;
746
+ //print("airborneFromImpulse: " + airborneFromImpulse + " unerMin: " +underMin + " notTryingToMove: " + notTryingToMove);
772
747
  if(canStopVel && notTryingToMove && underMin){
773
748
  //Not intending to move so snap to zero (Fake Dynamic Friction)
749
+ //print("STOPPING VELOCITY");
774
750
  newVelocity.x = 0;
775
751
  newVelocity.z = 0;
776
752
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg.easy.airship",
3
- "version": "0.1.1821",
3
+ "version": "0.1.1823",
4
4
  "displayName": "Airship",
5
5
  "unity": "2021.3",
6
6
  "unityRelease": "12f1",