Add BobbingRandomizer

This commit is contained in:
Sofia 2019-08-22 21:36:22 +03:00
parent f01ef21394
commit 007653eb54
12 changed files with 891 additions and 123 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -12,7 +12,6 @@ GameObject:
- component: {fileID: 592487110401094195} - component: {fileID: 592487110401094195}
- component: {fileID: 592487110401094194} - component: {fileID: 592487110401094194}
- component: {fileID: 592487110401094200} - component: {fileID: 592487110401094200}
- component: {fileID: 3068808787720623988}
- component: {fileID: 4248768674552437703} - component: {fileID: 4248768674552437703}
- component: {fileID: 592487110401094193} - component: {fileID: 592487110401094193}
- component: {fileID: 3362493323285318061} - component: {fileID: 3362493323285318061}
@ -104,24 +103,6 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
BehaviourDisplay: {fileID: 8912829886182716132} BehaviourDisplay: {fileID: 8912829886182716132}
CurrentBehaviour: Nothing CurrentBehaviour: Nothing
--- !u!114 &3068808787720623988
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 592487110401094192}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e796ba4c6f7efc449a10ed13ee42e34f, type: 3}
m_Name:
m_EditorClassIdentifier:
BobbedTransform: {fileID: 1801310824674407730}
BobbingMultiplier: 1
BobbingGravity: 0.8
BobbingLaunchSpeed: 0.12
BobbingFrequency: 0
BobbingDirection: {x: 0, y: 1}
--- !u!114 &4248768674552437703 --- !u!114 &4248768674552437703
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -134,11 +115,13 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3} m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Bobbing: {fileID: 3068808787720623988} Bobbing: {fileID: 0}
Direction: {x: 0, y: 0} Direction: {x: 0, y: 0}
MaxSpeed: 5 MaxSpeed: 5
AccelerationSpeed: 3 AccelerationSpeed: 3
DecelerationSpeed: 15 DecelerationSpeed: 15
AnimationSpeedModifier: 0
AnimationSpeed: 0
--- !u!114 &592487110401094193 --- !u!114 &592487110401094193
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -21,6 +21,7 @@ GameObject:
- component: {fileID: 3845295542453471664} - component: {fileID: 3845295542453471664}
- component: {fileID: 8799261875116284856} - component: {fileID: 8799261875116284856}
- component: {fileID: 384731428535676825} - component: {fileID: 384731428535676825}
- component: {fileID: 7096564391186586228}
m_Layer: 0 m_Layer: 0
m_Name: Enemy (Crab) m_Name: Enemy (Crab)
m_TagString: Enemy m_TagString: Enemy
@ -140,6 +141,8 @@ MonoBehaviour:
MaxSpeed: 2.5 MaxSpeed: 2.5
AccelerationSpeed: 10 AccelerationSpeed: 10
DecelerationSpeed: 10 DecelerationSpeed: 10
AnimationSpeedModifier: 0
AnimationSpeed: 0
--- !u!114 &592487110401094193 --- !u!114 &592487110401094193
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -258,6 +261,21 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Anim: {fileID: 5375970501711434365} Anim: {fileID: 5375970501711434365}
--- !u!114 &7096564391186586228
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 592487110401094192}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e649a6c117e18e1468ebe26330904cc8, type: 3}
m_Name:
m_EditorClassIdentifier:
Variety: 0.05
Movement: {fileID: 4248768674552437703}
Bobbing: {fileID: 3068808787720623988}
--- !u!1 &592487111066334293 --- !u!1 &592487111066334293
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -214,6 +214,7 @@ GameObject:
- component: {fileID: 7175095611357057067} - component: {fileID: 7175095611357057067}
- component: {fileID: 7974156166935930478} - component: {fileID: 7974156166935930478}
- component: {fileID: 8315503502695128381} - component: {fileID: 8315503502695128381}
- component: {fileID: 5013231347467375992}
m_Layer: 0 m_Layer: 0
m_Name: Enemy (MobCat) m_Name: Enemy (MobCat)
m_TagString: Untagged m_TagString: Untagged
@ -333,6 +334,8 @@ MonoBehaviour:
MaxSpeed: 2.5 MaxSpeed: 2.5
AccelerationSpeed: 10 AccelerationSpeed: 10
DecelerationSpeed: 10 DecelerationSpeed: 10
AnimationSpeedModifier: 0
AnimationSpeed: 0
--- !u!114 &5458726275277878114 --- !u!114 &5458726275277878114
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -451,6 +454,21 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
Anim: {fileID: 5842195514978149329} Anim: {fileID: 5842195514978149329}
SpriteRenderer: {fileID: 4848125059538075066} SpriteRenderer: {fileID: 4848125059538075066}
--- !u!114 &5013231347467375992
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2690120730931629369}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e649a6c117e18e1468ebe26330904cc8, type: 3}
m_Name:
m_EditorClassIdentifier:
Variety: 0.05
Movement: {fileID: 4069445145596408170}
Bobbing: {fileID: 6575270342303945011}
--- !u!1 &3991584792453052187 --- !u!1 &3991584792453052187
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -47,7 +47,7 @@ namespace Saltosion.OneWeapon.Enemies {
} else { } else {
Anim.Play("Idle"); Anim.Play("Idle");
} }
Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage); Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
if (Enemy.Movement.SpeedPercentage > 0.1) { if (Enemy.Movement.SpeedPercentage > 0.1) {
SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0; SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0;
} }

View File

@ -46,7 +46,7 @@ namespace Saltosion.OneWeapon.Enemies {
} else { } else {
Anim.Play("Walk"); Anim.Play("Walk");
} }
Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage); Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
} }
} }
} }

View File

@ -47,7 +47,7 @@ namespace Saltosion.OneWeapon.Enemies {
} else { } else {
Anim.Play("Walk"); Anim.Play("Walk");
} }
Anim.SetFloat("Speed", Enemy.Movement.SpeedPercentage); Anim.SetFloat("Speed", Enemy.Movement.AnimationSpeed);
if (Enemy.Movement.SpeedPercentage > 0.1) { if (Enemy.Movement.SpeedPercentage > 0.1) {
SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0; SpriteRenderer.flipX = Vector2.Dot(Enemy.Movement.Direction, Vector2.left) < 0;
} else { } else {

View File

@ -100,8 +100,8 @@ namespace Saltosion.OneWeapon.Player {
} else { } else {
IsMoving = false; IsMoving = false;
} }
BodyAnim.SetFloat("Speed", Movement.SpeedPercentage); BodyAnim.SetFloat("Speed", Movement.AnimationSpeed);
HeadAnim.SetFloat("Speed", Movement.SpeedPercentage); HeadAnim.SetFloat("Speed", Movement.AnimationSpeed);
bool Shoot = Input.GetButton("Shoot"); bool Shoot = Input.GetButton("Shoot");
if (Shoot) { if (Shoot) {

View File

@ -15,8 +15,13 @@ namespace Saltosion.OneWeapon.Utils {
public float AccelerationSpeed = 70; public float AccelerationSpeed = 70;
public float DecelerationSpeed = 70; public float DecelerationSpeed = 70;
[HideInInspector]
public float AnimationSpeedModifier;
[HideInInspector]
public float AnimationSpeed;
public Vector2 CurrentVelocity { private set; get; } public Vector2 CurrentVelocity { private set; get; }
public float SpeedPercentage { private set; get; } public float SpeedPercentage { private set; get; }
[HideInInspector]
private float CurrentSpeed = 0; private float CurrentSpeed = 0;
private Rigidbody2D Body; private Rigidbody2D Body;
@ -34,6 +39,7 @@ namespace Saltosion.OneWeapon.Utils {
CurrentSpeed *= 1 - (Vector2.Angle(Direction, LastDirection) / 180); CurrentSpeed *= 1 - (Vector2.Angle(Direction, LastDirection) / 180);
CurrentSpeed = Mathf.Clamp(CurrentSpeed, 0, MaxSpeed); CurrentSpeed = Mathf.Clamp(CurrentSpeed, 0, MaxSpeed);
SpeedPercentage = CurrentSpeed / MaxSpeed; SpeedPercentage = CurrentSpeed / MaxSpeed;
AnimationSpeed = SpeedPercentage * AnimationSpeedModifier;
CurrentVelocity = Direction.normalized * CurrentSpeed; CurrentVelocity = Direction.normalized * CurrentSpeed;

View File

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.Effects;
namespace Saltosion.OneWeapon.Utils {
public class BobbingRandomizer : MonoBehaviour {
public float Variety = 0.05f;
public AcceleratedMovement Movement;
public Bobbing Bobbing;
void Start() {
float RandomOffset = Random.value * (Variety * 2) - Variety;
if (Movement != null) {
Movement.AnimationSpeedModifier = 1 + RandomOffset;
}
if (Bobbing != null) {
Bobbing.BobbingLaunchSpeed = Bobbing.BobbingLaunchSpeed * (1 + RandomOffset);
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e649a6c117e18e1468ebe26330904cc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: