Commit 7766d750 authored by Jan Meissner's avatar Jan Meissner
Browse files

Various movement related fixes

parent 68329a88
......@@ -14,19 +14,19 @@ AnimatorController:
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 0
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: Live
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 1
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
- m_Name: InGroup
m_Type: 4
m_DefaultFloat: 0
m_DefaultInt: 0
m_DefaultBool: 1
m_Controller: {fileID: 9100000}
m_Controller: {fileID: 0}
m_AnimatorLayers:
- serializedVersion: 5
m_Name: Base Layer
......@@ -60,7 +60,7 @@ AnimatorStateTransition:
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.5
m_HasExitTime: 1
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
......@@ -110,7 +110,7 @@ AnimatorStateTransition:
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.5
m_HasExitTime: 1
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
......@@ -125,7 +125,7 @@ AnimatorStateTransition:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: Speed
m_EventTreshold: 0.01
m_EventTreshold: 0.2
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102844185289930602}
m_Solo: 0
......@@ -135,12 +135,12 @@ AnimatorStateTransition:
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101539321733455682
--- !u!1101 &1101482995910335170
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
......@@ -148,9 +148,9 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 2
m_ConditionEvent: InGroup
m_EventTreshold: 0
- m_ConditionMode: 4
m_ConditionEvent: Speed
m_EventTreshold: 0.2
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102891768866753616}
m_Solo: 0
......@@ -159,13 +159,13 @@ AnimatorStateTransition:
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0
m_ExitTime: 0.5
m_HasExitTime: 1
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101550492531972662
--- !u!1101 &1101539321733455682
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
......@@ -173,24 +173,24 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 1
- m_ConditionMode: 2
m_ConditionEvent: InGroup
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102446611082506456}
m_DstState: {fileID: 1102891768866753616}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.75
m_HasExitTime: 1
m_ExitTime: 0
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101621812645906834
--- !u!1101 &1101550492531972662
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
......@@ -198,9 +198,9 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 4
m_ConditionEvent: Speed
m_EventTreshold: 0.01
- m_ConditionMode: 1
m_ConditionEvent: InGroup
m_EventTreshold: 0
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102446611082506456}
m_Solo: 0
......@@ -209,13 +209,13 @@ AnimatorStateTransition:
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.5
m_HasExitTime: 1
m_ExitTime: 0.75
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101709650348920746
--- !u!1101 &1101621812645906834
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
......@@ -223,24 +223,24 @@ AnimatorStateTransition:
m_PrefabAsset: {fileID: 0}
m_Name:
m_Conditions:
- m_ConditionMode: 3
- m_ConditionMode: 4
m_ConditionEvent: Speed
m_EventTreshold: 0.01
m_EventTreshold: 0.2
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102858981962629576}
m_DstState: {fileID: 1102446611082506456}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0
m_HasExitTime: 1
m_ExitTime: 0.5
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
m_CanTransitionToSelf: 1
--- !u!1101 &1101949259774642510
--- !u!1101 &1101709650348920746
AnimatorStateTransition:
m_ObjectHideFlags: 1
m_CorrespondingSourceObject: {fileID: 0}
......@@ -250,17 +250,17 @@ AnimatorStateTransition:
m_Conditions:
- m_ConditionMode: 3
m_ConditionEvent: Speed
m_EventTreshold: 0.01
m_EventTreshold: 0.2
m_DstStateMachine: {fileID: 0}
m_DstState: {fileID: 1102891768866753616}
m_DstState: {fileID: 1102858981962629576}
m_Solo: 0
m_Mute: 0
m_IsExit: 0
serializedVersion: 3
m_TransitionDuration: 0.25
m_TransitionOffset: 0
m_ExitTime: 0.5
m_HasExitTime: 1
m_ExitTime: 0
m_HasExitTime: 0
m_HasFixedDuration: 1
m_InterruptionSource: 0
m_OrderedInterruption: 1
......@@ -331,7 +331,7 @@ AnimatorState:
m_CycleOffset: 0
m_Transitions:
- {fileID: 1101024630095642056}
- {fileID: 1101949259774642510}
- {fileID: 1101482995910335170}
m_StateMachineBehaviours: []
m_Position: {x: 50, y: 50, z: 0}
m_IKOnFeet: 0
......
......@@ -2,7 +2,7 @@ fileFormatVersion: 2
guid: fb2f5be7396bfa842af5b0967d321eee
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 9100000
mainObjectFileID: 0
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 435e0ab87d10d1d46966abe3e1b854db
guid: deccfabc79d963e4ebc76c275f4c8f31
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2948431498428106177
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6917716191751595653}
- component: {fileID: 967038370172742350}
- component: {fileID: 4980288968761876959}
- component: {fileID: 8935424848761574170}
m_Layer: 0
m_Name: Bomb
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6917716191751595653
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2948431498428106177}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 7.5143647, y: 1.2922589, z: 1.9558203}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!212 &967038370172742350
SpriteRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2948431498428106177}
m_Enabled: 1
m_CastShadows: 0
m_ReceiveShadows: 0
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 0
m_SelectedEditorRenderState: 0
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_Sprite: {fileID: 21300000, guid: ea66110a160b30440b76260633133a05, type: 3}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 0
m_Size: {x: 1.8, y: 2.13}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!58 &4980288968761876959
CircleCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2948431498428106177}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
serializedVersion: 2
m_Radius: 0.29583332
--- !u!50 &8935424848761574170
Rigidbody2D:
serializedVersion: 4
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2948431498428106177}
m_BodyType: 0
m_Simulated: 1
m_UseFullKinematicContacts: 0
m_UseAutoMass: 0
m_Mass: 1
m_LinearDrag: 0
m_AngularDrag: 0.05
m_GravityScale: 1
m_Material: {fileID: 0}
m_Interpolate: 0
m_SleepingMode: 1
m_CollisionDetection: 0
m_Constraints: 0
fileFormatVersion: 2
guid: 836bba66055997b4a8de1df24f771eb9
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -9,6 +9,7 @@ public class GroupController : MonoBehaviour, IKillTarget
private GameManager gameManager;
public bool IsGroupSelected;
private bool blockedInput;
private Rigidbody2D rbGroup;
bool isDirectionPositiv;
public GameObject[] PlayableLemmings { get; set; }
public GameObject[] DummyLemmings { get; set; }
......@@ -21,6 +22,7 @@ public class GroupController : MonoBehaviour, IKillTarget
public Animator ActiveLemmingAnimator { get; set; }
private Vector3 ActiveLemmingGroupPosition { get; set; }
private Color ActiveLemmingColor { get; set; }
private Rigidbody2D ActiveLemmingRb { get; set; }
// Start is called before the first frame update
void Start()
......@@ -54,6 +56,35 @@ public class GroupController : MonoBehaviour, IKillTarget
{
RemoveLemmingFromGroup();
}
rbGroup = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
foreach (var animator in AllLemmingAnimator)
{
if (animator != null)
{
//animator.SetFloat("Speed", Mathf.Abs(direction));
animator.SetFloat("Speed", Mathf.Abs(rbGroup.velocity.x));
}
}
if (IsGroupSelected)
{
foreach (var sprite in AllLemmingSpriteRenderer)
{
if (sprite != null)
{
sprite.flipX = isDirectionPositiv;
}
}
}
else
{
ActiveLemmingAnimator.SetFloat("Speed", Mathf.Abs(ActiveLemmingRb.velocity.x));
}
}
public void SetActiveLemming(float index)
......@@ -63,6 +94,7 @@ public class GroupController : MonoBehaviour, IKillTarget
ActiveLemmingGroupPosition = ActiveLemming.transform.localPosition;
ActiveLemmingColor = ActiveLemming.GetComponent<SpriteRenderer>().color;
ActiveLemmingAnimator = ActiveLemming.GetComponent<Animator>();
ActiveLemmingRb = ActiveLemming.GetComponent<Rigidbody2D>();
}
public void RemoveLemmingFromGroup()
......@@ -144,21 +176,6 @@ public class GroupController : MonoBehaviour, IKillTarget
if (IsGroupSelected && !blockedInput)
{
groupMovement.MoveHorizontal(direction);
foreach (var animator in AllLemmingAnimator)
{
if (animator != null)
{
animator.SetFloat("Speed", Mathf.Abs(direction));
}
}
foreach (var sprite in AllLemmingSpriteRenderer)
{
if (sprite != null)
{
sprite.flipX = isDirectionPositiv;
}
}
}
else if (!blockedInput)
{
......
fileFormatVersion: 2
guid: 1e24085edff8e4e499582d8dcf099510
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 25398038ee94b5947b7b6055a52a03ca
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -14,12 +14,18 @@ public class GroundTrigger : MonoBehaviour
private void OnTriggerEnter2D(Collider2D other)
{
move.IsGrounded = true;
if (other.CompareTag("Ground"))
{
move.IsGrounded = true;
}
}
private void OnTriggerStay2D(Collider2D other)
{
move.IsGrounded = true;
if (other.CompareTag("Ground"))
{
move.IsGrounded = true;
}
}
public void ChangeFootStatus(bool status)
......
......@@ -7,15 +7,14 @@ public class LemmingMovement : MonoBehaviour
{
[SerializeField] public Rigidbody2D rb;
[SerializeField] public float jumpForce = 1.1f;
[SerializeField] public float speed = 2;
[SerializeField] public float maxSpeed = 2;
[SerializeField] public float speed = 5;
[SerializeField] public float landingDelay = 50;
[SerializeField] public float superJumpForce = 2;
[SerializeField] public bool IsGrounded;
public bool IsCrouching { get; set; }
public Vector2 WindConstant { get; set; }
public Vector2 AdditionalVelocity { get; set; }
private Animator anim;
[SerializeField] private float landingTimer;
......@@ -23,15 +22,21 @@ public class LemmingMovement : MonoBehaviour
void Start()
{
rb.freezeRotation = true;
anim = GetComponent<Animator>();
}
void FixedUpdate()
{
rb.AddForce(WindConstant + AdditionalVelocity);
//rb.AddForce(WindConstant + AdditionalVelocity);
if (IsGrounded && landingTimer >= 0f)
if (IsGrounded)
{
landingTimer -= Time.deltaTime;
if (landingTimer >= 0f)
{
landingTimer -= Time.deltaTime;
}
//if (rb.velocity < )
}
}
......@@ -40,24 +45,21 @@ public class LemmingMovement : MonoBehaviour
Vector2 jump;
if (superJumpActivated)
{
jump = new Vector2(0, 1 * jumpForce * superJumpForce * 5f);
jump = new Vector2(0, jumpForce * superJumpForce * 5f);
}
else
{
jump = new Vector2(0, 1 * jumpForce * 5f);
jump = new Vector2(0, jumpForce * 5f);
}
if (landingTimer <= 0f && IsGrounded)
{
//rb.AddForce(jump, ForceMode2D.Impulse);
rb.velocity = jump;
IsGrounded = false;
landingTimer = landingDelay / 1000;
}
}
// Intensity on a scale from 1 to 10
private void BrakeMovement()
{
if (rb.velocity.x < -0.1f && rb.velocity.x > 0.1f)
......@@ -73,11 +75,16 @@ public class LemmingMovement : MonoBehaviour
public void MoveHorizontal(float direction)
{
if (direction > 0) direction = 1;
else if (direction < 0) direction = -1;
// If no movement input exists, auto brake
if (direction < 0.1f && direction > -0.1f)
// Clamp input to -1 / 1
if (direction > 0.1f)
{
direction = 1;
}
else if(direction < -0.1f)
{
direction = -1;
}
else
{
return;
}
......@@ -89,25 +96,14 @@ public class LemmingMovement : MonoBehaviour
{
BrakeMovement();
}
// Accelerate in movement direction
else if (rb.velocity.x < maxSpeed && rb.velocity.x > -maxSpeed)
if (IsGrounded)
{
// Acceleration on ground is faster than in air
if (IsGrounded)
{
rb.velocity = new Vector2(direction, 0f) * speed * 100 * Time.deltaTime;
}
else
{
rb.velocity = new Vector2(direction * speed * 40 * Time.deltaTime, rb.velocity.y);
}
rb.velocity = new Vector2(direction * speed, 0f);
}
// Reduce velocity to maxSpeed if too fast
if (velocity.x > maxSpeed || velocity.x < -maxSpeed)
else
{
rb.velocity = new Vector2(direction * maxSpeed, rb.velocity.y);
rb.velocity = new Vector2(direction * speed * 0.7f, rb.velocity.y);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment