gg.easy.airship 0.1.1663 → 0.1.1664

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.
@@ -4,6 +4,8 @@ using UnityEngine.Serialization;
4
4
  namespace Code.Player.Character.API {
5
5
  [LuauAPI]
6
6
  public class CharacterMovementData : MonoBehaviour {
7
+
8
+
7
9
  [Header("Size")]
8
10
  [Tooltip("How tall is the character")] [Min(.01f)]
9
11
  public float characterHeight = 1.8f;
@@ -11,8 +13,6 @@ namespace Code.Player.Character.API {
11
13
  [Tooltip("Radius of the character")] [Min(.01f)]
12
14
  public float characterRadius = .2f;
13
15
 
14
- /*[Tooltip("Default movement speed (units per second)")] [Min(0f)]
15
- public float colliderHeightOffset = .15f;*/
16
16
 
17
17
  [Header("Movement")]
18
18
  [Tooltip("Should movement be applied over time as a force? Or a constant speed.")]
@@ -21,26 +21,30 @@ namespace Code.Player.Character.API {
21
21
  [Tooltip("Default movement speed (units per second)")] [Min(0f)]
22
22
  public float speed = 4.666667f;
23
23
 
24
-
25
24
  [Tooltip("Sprint movement speed (units per second)")] [Min(0f)]
26
25
  public float sprintSpeed = 6.666667f;
27
26
 
28
- [Tooltip("How much to multiply speed while you are in the air")] [Range(0,2f)]
29
- public float airSpeedMultiplier = 1;
30
-
31
27
  [Tooltip("Only allow sprinting forward.")]
32
28
  public bool onlySprintForward = false;
33
29
 
30
+
34
31
  [Header("Crouch")]
35
32
  [Tooltip("Auto crouch will make the character crouch if they walk into a small area")]
36
33
  public bool autoCrouch = true;
37
34
 
35
+ [Tooltip("While crouching, prevent falling of ledges")]
36
+ public bool preventFallingWhileCrouching = true;
37
+
38
+ [Tooltip("While crouching dont step up onto ledges")]
39
+ public bool preventStepUpWhileCrouching = true;
40
+
38
41
  [Tooltip("Crouching speed is determined by multiplying the speed against this number")] [Range(0f, 1f)]
39
42
  public float crouchSpeedMultiplier = 0.455f;
40
43
 
41
44
  [Tooltip("Character height multiplier when crouching (e.g. 0.75 would be 75% of normal character height)")] [Range(0.15f, 1f)]
42
45
  public float crouchHeightMultiplier = 0.75f;
43
46
 
47
+
44
48
  [Header("Jump")]
45
49
  [Tooltip("How many jumps you can make before hitting the ground again")] [Min(0f)]
46
50
  public int numberOfJumps = 1;
@@ -51,6 +55,7 @@ namespace Code.Player.Character.API {
51
55
  [Tooltip("The time after falling that the player can still jump")] [Min(0f)]
52
56
  public float jumpCoyoteTime = 0.14f;
53
57
 
58
+
54
59
  [Header("Fly")]
55
60
  [Tooltip("Flying speed is determined by multiplying the speed against this number")]
56
61
  public float flySpeedMultiplier = 3.5f;
@@ -67,6 +72,7 @@ namespace Code.Player.Character.API {
67
72
  [Tooltip("Minimum interval (in seconds) between jumps, measured from the time the player became grounded")] [Min(0f)]
68
73
  public float jumpUpBlockCooldown = 0.4f;
69
74
 
75
+
70
76
  [Header("Gravity")]
71
77
  [Tooltip("Apply Physics.gravity force every tick")]
72
78
  public bool useGravity = true;
@@ -78,7 +84,11 @@ namespace Code.Player.Character.API {
78
84
  [Tooltip("Use this to adjust gravity while moving in the +Y. So you can have floaty jumps upwards but still have hard drops downward")]
79
85
  public float upwardsGravityMultiplier = 1;
80
86
 
87
+
81
88
  [Header("Physics")]
89
+ [Tooltip("Push the character away from walls to prevent rigibody friction")]
90
+ public bool preventWallClipping = true;
91
+
82
92
  [Tooltip("What layers will count as walkable ground")]
83
93
  public LayerMask groundCollisionLayerMask = 1 << 0 | 1 << 8 | 1 << 11; // Layers Default, VisuallyHidden and VoxelWorld
84
94
 
@@ -88,16 +98,6 @@ namespace Code.Player.Character.API {
88
98
  public float minimumVelocity = 1;
89
99
  [Tooltip("Also stop momentum when in the air")]
90
100
  public bool useMinimumVelocityInAir = false;
91
-
92
- [Tooltip("The maximum force that pushes against the character when on a slope")] [Min(0f)]
93
- public float slopeForce = 45;
94
-
95
- [Tooltip("Slopes below this threshold will be ignored. O is flat ground, 1 is a vertical wall")]
96
- [Range(0,1)]
97
- public float minSlopeDelta = .1f;
98
- [Tooltip("Slopes above this threshold will be treated as walls")]
99
- [Range(0,1)]
100
- public float maxSlopeDelta = .3f;
101
101
 
102
102
  [Tooltip("How high in units can you auto step up")]
103
103
  [Range(.05f, 1)]
@@ -114,12 +114,11 @@ namespace Code.Player.Character.API {
114
114
  [Tooltip("How much to multiply drag resistance while you are in the air")] [Range(0,2f)]
115
115
  public float airDragMultiplier = 1;
116
116
 
117
+ [Tooltip("How much to multiply speed while you are in the air")] [Range(0,2f)]
118
+ public float airSpeedMultiplier = 1;
117
119
 
118
- [Header("Movement Modes")]
119
-
120
- [Tooltip("Auto detect slopes to create a downward drag. Disable as an optimization to skip raycast checks")]
121
- public bool detectSlopes = false;
122
120
 
121
+ [Header("Step Ups")]
123
122
  [Tooltip("Push the character up when they stop over a set threshold")]
124
123
  public bool detectStepUps = true;
125
124
  [Tooltip("Step the character up every frame if it theres nothing to push up to")]
@@ -128,10 +127,19 @@ namespace Code.Player.Character.API {
128
127
  [Tooltip("While in the air, if you are near an edge it will push you up to the edge. Requries detectStepUps to be on")]
129
128
  public bool assistedLedgeJump = true;
130
129
 
131
- [Tooltip("Push the character away from walls to prevent rigibody friction")]
132
- public bool preventWallClipping = true;
133
130
 
134
- [Tooltip("While crouching, prevent falling of ledges")]
135
- public bool preventFallingWhileCrouching = true;
131
+ [Header("Slopes")]
132
+ [Tooltip("Auto detect slopes to create a downward drag. Disable as an optimization to skip raycast checks")]
133
+ public bool detectSlopes = false;
134
+
135
+ [Tooltip("The maximum force that pushes against the character when on a slope")] [Min(0f)]
136
+ public float slopeForce = 45;
137
+
138
+ [Tooltip("Slopes below this threshold will be ignored. O is flat ground, 1 is a vertical wall")]
139
+ [Range(0,1)]
140
+ public float minSlopeDelta = .1f;
141
+ [Tooltip("Slopes above this threshold will be treated as walls")]
142
+ [Range(0,1)]
143
+ public float maxSlopeDelta = .3f;
136
144
  }
137
145
  }
@@ -6,7 +6,6 @@ namespace Code.Player.Character.API {
6
6
  public class CharacterPhysics {
7
7
  private const float offsetMargin = .02f;
8
8
  private const float gizmoDuration = 1f;
9
- private const bool renderGroundGizmos = true;
10
9
 
11
10
  private CharacterMovement movement;
12
11
  private Vector3 uniformHalfExtents;
@@ -75,12 +74,11 @@ namespace Code.Player.Character.API {
75
74
 
76
75
  #region RAYCASTS
77
76
  public (bool isGrounded, RaycastHit hit, bool detectedGround) CheckIfGrounded(Vector3 currentPos, Vector3 vel, Vector3 moveDir) {
78
- // Fallthrough - do raycast to check for PrefabBlock object below:
79
77
  var intersectionMargin = .075f;
80
78
  var castDistance = .2f;
81
79
  var castStartPos = currentPos;
82
80
  //Move the start position up
83
- castStartPos.y += castDistance-intersectionMargin;
81
+ castStartPos.y += castDistance-offsetMargin;
84
82
  //Extend the ray further if you are falling faster
85
83
  castDistance += Mathf.Max(0, -vel.y);// Mathf.Min(0, movement.transform.InverseTransformVector(vel).y); //Need this part of we change gravity dir
86
84
 
@@ -89,9 +87,9 @@ namespace Code.Player.Character.API {
89
87
 
90
88
  //Check directly below character as an early out and for comparison information
91
89
  if(Physics.Raycast(castStartPos, gravityDir, out var rayHitInfo, castDistance, movement.moveData.groundCollisionLayerMask, QueryTriggerInteraction.Ignore)){
92
- if(movement.drawDebugGizmos && renderGroundGizmos){
93
- //GizmoUtils.DrawLine(castStartPos, castStartPos+gravityDir*castDistance, Color.gray, gizmoDuration);
94
- //GizmoUtils.DrawSphere(rayHitInfo.point, .05f, Color.red, 4, gizmoDuration);
90
+ if(movement.drawDebugGizmos_GROUND){
91
+ GizmoUtils.DrawLine(castStartPos, castStartPos+gravityDir*castDistance, Color.gray, gizmoDuration);
92
+ GizmoUtils.DrawSphere(rayHitInfo.point, .05f, Color.red, 4, gizmoDuration);
95
93
  }
96
94
 
97
95
  if(!this.ignoredColliders.ContainsKey(rayHitInfo.collider.GetInstanceID())){
@@ -101,24 +99,24 @@ namespace Code.Player.Character.API {
101
99
 
102
100
  //Extend the casting for the box
103
101
  var verticalExtents = .05f;
104
- var extents = uniformHalfExtents;
102
+ var extents = uniformHalfExtents*.98f;
105
103
  extents.y = verticalExtents;
106
104
  castStartPos.y += verticalExtents;
107
105
  castDistance += verticalExtents;
108
106
 
109
- if(movement.drawDebugGizmos && renderGroundGizmos){
110
- //GizmoUtils.DrawBox(castStartPos, Quaternion.identity, extents, Color.magenta, gizmoDuration);
111
- //GizmoUtils.DrawBox(castStartPos+gravityDir*castDistance, Quaternion.identity, extents, Color.magenta, gizmoDuration);
107
+ if(movement.drawDebugGizmos_GROUND){
108
+ GizmoUtils.DrawBox(castStartPos, Quaternion.identity, extents, Color.magenta, gizmoDuration);
109
+ GizmoUtils.DrawBox(castStartPos+gravityDir*castDistance, Quaternion.identity, extents, Color.magenta, gizmoDuration);
112
110
  }
113
111
 
114
112
  //Check down around the entire character
115
113
  if (Physics.BoxCast(castStartPos, extents, gravityDir, out var hitInfo, Quaternion.identity, castDistance, movement.moveData.groundCollisionLayerMask, QueryTriggerInteraction.Ignore)) {
116
- if(movement.drawDebugGizmos && renderGroundGizmos){
117
- //GizmoUtils.DrawSphere(hitInfo.point + gravityDirOffset, .05f, Color.red, 4, gizmoDuration);
114
+ if(movement.drawDebugGizmos_GROUND){
115
+ GizmoUtils.DrawSphere(hitInfo.point + gravityDirOffset, .05f, Color.red, 4, gizmoDuration);
118
116
  }
119
117
  if(!movement.grounded){
120
- if(movement.drawDebugGizmos && renderGroundGizmos){
121
- //GizmoUtils.DrawSphere(hitInfo.point, .1f, Color.red, 8, gizmoDuration);
118
+ if(movement.drawDebugGizmos_GROUND){
119
+ GizmoUtils.DrawSphere(hitInfo.point, .1f, Color.red, 8, gizmoDuration);
122
120
 
123
121
  }
124
122
  if(movement.useExtraLogging){
@@ -130,8 +128,8 @@ namespace Code.Player.Character.API {
130
128
  //Physics Casts give you interpolated normals. This uses a ray to find an exact normal
131
129
  hitInfo.normal = CalculateRealNormal(hitInfo.normal, hitInfo.point + gravityDirOffset + moveDir.normalized*.01f, gravityDir, .11f, movement.moveData.groundCollisionLayerMask);
132
130
 
133
- if(movement.drawDebugGizmos && renderGroundGizmos){
134
- //GizmoUtils.DrawLine(hitInfo.point, hitInfo.point + hitInfo.normal, Color.red, gizmoDuration);
131
+ if(movement.drawDebugGizmos_GROUND){
132
+ GizmoUtils.DrawLine(hitInfo.point, hitInfo.point + hitInfo.normal, Color.red, gizmoDuration);
135
133
  }
136
134
 
137
135
  //var inCollider = IsPointInCharacter...(hitInfo.point);
@@ -156,7 +154,7 @@ namespace Code.Player.Character.API {
156
154
  //Move from root to center of collider
157
155
  var startPos = rootPos + new Vector3(0,centerHeight,0);
158
156
  var extents = ignoreStepUp ? new Vector3(movement.characterHalfExtents.x, movement.characterHalfExtents.y - movement.moveData.maxStepUpHeight/2f, movement.characterHalfExtents.z) : movement.characterHalfExtents;
159
- if(movement.drawDebugGizmos){
157
+ if(movement.drawDebugGizmos_FORWARD){
160
158
  // GizmoUtils.DrawBox(startPos, Quaternion.identity, extents, Color.green, gizmoDuration);
161
159
  // GizmoUtils.DrawBox(startPos+normalizedForward * distance, Quaternion.identity, extents, Color.green, gizmoDuration);
162
160
  }
@@ -169,7 +167,7 @@ namespace Code.Player.Character.API {
169
167
  //localHit.y = 0;
170
168
  hitInfo.normal = CalculateRealNormal(hitInfo.normal, hitInfo.point-forwardVector, forwardVector, forwardVector.magnitude, movement.moveData.groundCollisionLayerMask);
171
169
 
172
- if(movement.drawDebugGizmos){
170
+ if(movement.drawDebugGizmos_FORWARD){
173
171
  //GizmoUtils.DrawSphere(hitInfo.point, .05f, Color.black, 4, gizmoDuration);
174
172
  //GizmoUtils.DrawLine(hitInfo.point, hitInfo.point + hitInfo.normal, Color.black, gizmoDuration);
175
173
  }
@@ -202,7 +200,7 @@ namespace Code.Player.Character.API {
202
200
  Debug.Log("currentUpNormal: " + currentUpNormal + " forwardHitInfo: " + forwardHitInfo.normal + " EQUAL: "+ (currentUpNormal == forwardHitInfo.normal));
203
201
  }
204
202
 
205
- if(didHitForward && movement.drawDebugGizmos){
203
+ if(didHitForward && movement.drawDebugGizmos_STEPUP){
206
204
  //GizmoUtils.DrawSphere(forwardHitInfo.point, .025f, Color.cyan, 4, gizmoDuration);
207
205
  }
208
206
 
@@ -220,7 +218,7 @@ namespace Code.Player.Character.API {
220
218
  var stepUpRayStart = forwardHitInfo.point + velDir * (forwardHitInfo.distance + offsetMargin);
221
219
  stepUpRayStart.y = startPos.y + movement.moveData.maxStepUpHeight+movement.characterRadius;
222
220
 
223
- if(movement.drawDebugGizmos){
221
+ if(movement.drawDebugGizmos_STEPUP){
224
222
  GizmoUtils.DrawSphere(stepUpRayStart, .05f, Color.yellow, 4, gizmoDuration);
225
223
  GizmoUtils.DrawSphere(startPos, .04f, Color.blue, 4, gizmoDuration);
226
224
  }
@@ -229,7 +227,7 @@ namespace Code.Player.Character.API {
229
227
  //Vector3.down, out RaycastHit stepUpRayHitInfo, Quaternion.identity, movement.moveData.characterHeight, movement.moveData.groundCollisionLayerMask, QueryTriggerInteraction.Ignore)){
230
228
  if(Physics.Raycast(stepUpRayStart, new Vector3(0,-1,0), out RaycastHit stepUpRayHitInfo, movement.moveData.characterHeight, movement.moveData.groundCollisionLayerMask, QueryTriggerInteraction.Ignore)){
231
229
  //Hit a surface that is in range
232
- if(movement.drawDebugGizmos){
230
+ if(movement.drawDebugGizmos_STEPUP){
233
231
  GizmoUtils.DrawLine(stepUpRayStart, stepUpRayHitInfo.point, Color.yellow, gizmoDuration);
234
232
  }
235
233
 
@@ -248,7 +246,7 @@ namespace Code.Player.Character.API {
248
246
 
249
247
  var bottompoint = topPoint - flatDir * stepUpRampDistance;
250
248
  bottompoint.y = topPoint.y - movement.moveData.maxStepUpHeight;
251
- if(movement.drawDebugGizmos){
249
+ if(movement.drawDebugGizmos_STEPUP){
252
250
  GizmoUtils.DrawBox(startPos + Vector3.up, Quaternion.identity, Vector3.one * .02f, Color.red, 4);
253
251
  GizmoUtils.DrawBox(startPos + Vector3.up + new Vector3(0,-movement.moveData.maxStepUpHeight-1,0), Quaternion.identity, Vector3.one * .02f, Color.blue, 4);
254
252
  }
@@ -262,7 +260,7 @@ namespace Code.Player.Character.API {
262
260
  var rawDelta = GetFlatDistance(startPos + (vel * deltaTime), bottompoint) / stepUpRampDistance;
263
261
  var pointOnRampDelta = Mathf.Clamp01(rawDelta);
264
262
  var pointOnRamp = Vector3.Lerp(bottompoint, topPoint, pointOnRampDelta);// + new Vector3(0,offsetMargin,0);
265
- if(movement.drawDebugGizmos){
263
+ if(movement.drawDebugGizmos_STEPUP){
266
264
  GizmoUtils.DrawSphere(topPoint, .02f, Color.cyan, 4, gizmoDuration);
267
265
  GizmoUtils.DrawLine(topPoint, topPoint+rampNormal, Color.yellow, gizmoDuration);
268
266
  GizmoUtils.DrawSphere(pointOnRamp, .02f, Color.green, 4, gizmoDuration);
@@ -302,7 +300,7 @@ namespace Code.Player.Character.API {
302
300
  if(!Physics.Raycast(quickStepHitInfo.point, Vector3.up, movement.standingCharacterHeight+offsetMargin, movement.moveData.groundCollisionLayerMask, QueryTriggerInteraction.Ignore)
303
301
  && IsWalkableSurface(quickStepHitInfo.normal)){
304
302
  var hitPoint = quickStepHitInfo.point + new Vector3(0,offsetMargin, 0);
305
- if(movement.drawDebugGizmos){
303
+ if(movement.drawDebugGizmos_STEPUP){
306
304
  GizmoUtils.DrawSphere(hitPoint, .05f, Color.white, 4, gizmoDuration);
307
305
  }
308
306
  return (true, false, hitPoint, vel);
@@ -2,7 +2,7 @@
2
2
  public enum CharacterState {
3
3
  Idle = 0,
4
4
  Running = 1,
5
- Jumping = 2,
5
+ Airborne = 2,
6
6
  Sprinting = 3,
7
7
  Crouching = 4,
8
8
  }
@@ -114,7 +114,7 @@ namespace Code.Player.Character {
114
114
  if (currentState == CharacterState.Idle) {
115
115
  targetVelNormalized = Vector2.zero;
116
116
  modifiedTargetPlaybackSpeed = 1;
117
- } else if (currentState == CharacterState.Jumping){
117
+ } else if (currentState == CharacterState.Airborne){
118
118
  modifiedTargetPlaybackSpeed = 1;
119
119
  }
120
120
 
@@ -21,7 +21,10 @@ namespace Code.Player.Character {
21
21
  public Transform slopeVisualizer;
22
22
 
23
23
  [Header("Debug")]
24
- public bool drawDebugGizmos = false;
24
+ public bool drawDebugGizmos_FORWARD = false;
25
+ public bool drawDebugGizmos_GROUND = false;
26
+ public bool drawDebugGizmos_STEPUP = false;
27
+ public bool drawDebugGizmos_STATES= false;
25
28
  public bool useExtraLogging = false;
26
29
 
27
30
  [Header("Variables")]
@@ -399,7 +402,7 @@ namespace Code.Player.Character {
399
402
 
400
403
  //If you are in the air override the state
401
404
  if (inAir) {
402
- state = CharacterState.Jumping;
405
+ state = CharacterState.Airborne;
403
406
  }else{
404
407
  //Otherwise use our found state
405
408
  state = groundedState;
@@ -579,7 +582,7 @@ namespace Code.Player.Character {
579
582
  var newMoveVector = Vector3.ProjectOnPlane(characterMoveVelocity, groundHit.normal);
580
583
  newMoveVector.y = Mathf.Min(0, newMoveVector.y);
581
584
  characterMoveVelocity = newMoveVector;
582
- if(drawDebugGizmos){
585
+ if(drawDebugGizmos_STEPUP){
583
586
  GizmoUtils.DrawLine(transform.position, transform.position + characterMoveVelocity * 2, Color.red);
584
587
  }
585
588
  //characterMoveVector.y = Mathf.Clamp( characterMoveVector.y, 0, moveData.maxSlopeSpeed);
@@ -695,7 +698,7 @@ namespace Code.Player.Character {
695
698
  #region STEP_UP
696
699
  //Step up as the last step so we have the most up to date velocity to work from
697
700
  var didStepUp = false;
698
- if(moveData.detectStepUps && !md.crouch){
701
+ if(moveData.detectStepUps && (!md.crouch || !moveData.preventStepUpWhileCrouching)){
699
702
  (bool hitStepUp, bool onRamp, Vector3 pointOnRamp, Vector3 stepUpVel) = physics.StepUp(rootTransform.position, newVelocity + characterMoveVelocity, deltaTime, detectedGround ? groundHit.normal: Vector3.up);
700
703
  if(hitStepUp){
701
704
  didStepUp = hitStepUp;
@@ -710,7 +713,7 @@ namespace Code.Player.Character {
710
713
  debugPoint += newVelocity * deltaTime;
711
714
  //print("PointOnRamp: " + pointOnRamp + " position: " + transform.position + " velY: " + newVelocity.y);
712
715
 
713
- if(drawDebugGizmos){
716
+ if(drawDebugGizmos_STEPUP){
714
717
  GizmoUtils.DrawSphere(debugPoint, .03f, Color.red, 4, 4);
715
718
  }
716
719
  state = groundedState;//Force grounded state since we are in the air for the step up
@@ -1012,7 +1015,7 @@ namespace Code.Player.Character {
1012
1015
 
1013
1016
  // If the character state is different
1014
1017
  if (isNewState) {
1015
- if(drawDebugGizmos && newStateData.state == CharacterState.Jumping){
1018
+ if(drawDebugGizmos_STATES && newStateData.state == CharacterState.Airborne){
1016
1019
  GizmoUtils.DrawSphere(transform.position, .05f, Color.green,4,1);
1017
1020
  }
1018
1021
  stateChanged?.Invoke((int)newStateData.state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg.easy.airship",
3
- "version": "0.1.1663",
3
+ "version": "0.1.1664",
4
4
  "displayName": "Airship",
5
5
  "unity": "2021.3",
6
6
  "unityRelease": "12f1",