Change namespaces, add AcceleratedMovement

This commit is contained in:
Sofia 2019-08-07 23:54:18 +03:00
parent be87b7504c
commit 4475fd4305
13 changed files with 80 additions and 16 deletions

View File

@ -424,6 +424,7 @@ GameObject:
- component: {fileID: 412028545510300634} - component: {fileID: 412028545510300634}
- component: {fileID: 8489029732530782806} - component: {fileID: 8489029732530782806}
- component: {fileID: 5050980832709922958} - component: {fileID: 5050980832709922958}
- component: {fileID: 7263640616704110489}
- component: {fileID: 5620918083888341557} - component: {fileID: 5620918083888341557}
m_Layer: 0 m_Layer: 0
m_Name: Player m_Name: Player
@ -499,7 +500,7 @@ MonoBehaviour:
Body: {fileID: 8489029732530782792} Body: {fileID: 8489029732530782792}
Hand: {fileID: 8334477035414792174} Hand: {fileID: 8334477035414792174}
SubHand: {fileID: 340836170559364036} SubHand: {fileID: 340836170559364036}
MoveSpeed: 50 Movement: {fileID: 7263640616704110489}
BodySprite: {fileID: 8489029732241002784} BodySprite: {fileID: 8489029732241002784}
BodyAnim: {fileID: 7470056256336689202} BodyAnim: {fileID: 7470056256336689202}
HeadSprite: {fileID: 8489029732599905344} HeadSprite: {fileID: 8489029732599905344}
@ -512,7 +513,6 @@ MonoBehaviour:
PlayerFun: {fileID: 5050980832709922958} PlayerFun: {fileID: 5050980832709922958}
HandRetractSpeed: 10 HandRetractSpeed: 10
HandRotationRetractSpeed: 300 HandRotationRetractSpeed: 300
Bobbing: {fileID: 5620918083888341557}
--- !u!114 &5050980832709922958 --- !u!114 &5050980832709922958
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -536,6 +536,23 @@ MonoBehaviour:
DebugAdd10Fun: 0 DebugAdd10Fun: 0
DebugSubtract10Fun: 0 DebugSubtract10Fun: 0
GodMode: 0 GodMode: 0
--- !u!114 &7263640616704110489
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8489029732530782804}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ba61752571d0d70478c63122f73914db, type: 3}
m_Name:
m_EditorClassIdentifier:
Body: {fileID: 8489029732530782792}
Bobbing: {fileID: 5620918083888341557}
Direction: {x: 0, y: 0}
MaxSpeed: 7
AccelerationSpeed: 70
--- !u!114 &5620918083888341557 --- !u!114 &5620918083888341557
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon.AI.Triggers { namespace Saltosion.OneWeapon.AI.Triggers {
public class EnemySighted : Trigger { public class EnemySighted : Trigger {

View File

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon.AI.Triggers { namespace Saltosion.OneWeapon.AI.Triggers {
public class PlayerSighted : Trigger { public class PlayerSighted : Trigger {

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Animations; using UnityEngine.Animations;
using Saltosion.OneWeapon.Effects; using Saltosion.OneWeapon.Effects;
using Saltosion.OneWeapon.Utils;
namespace Saltosion.OneWeapon { namespace Saltosion.OneWeapon {
public class Player : MonoBehaviour { public class Player : MonoBehaviour {
@ -10,7 +11,8 @@ namespace Saltosion.OneWeapon {
public Rigidbody2D Body; public Rigidbody2D Body;
public Transform Hand; public Transform Hand;
public Transform SubHand; public Transform SubHand;
public float MoveSpeed = 50f;
public AcceleratedMovement Movement;
public SpriteRenderer BodySprite; public SpriteRenderer BodySprite;
public Animator BodyAnim; public Animator BodyAnim;
@ -37,7 +39,6 @@ namespace Saltosion.OneWeapon {
private float CurrentHandRotation = 0f; private float CurrentHandRotation = 0f;
private float CurrentHandDistance = 0f; private float CurrentHandDistance = 0f;
public Bobbing Bobbing;
public bool IsMoving { public bool IsMoving {
private set; get; private set; get;
@ -47,9 +48,7 @@ namespace Saltosion.OneWeapon {
float X = Input.GetAxis("Horizontal"); float X = Input.GetAxis("Horizontal");
float Y = Input.GetAxis("Vertical"); float Y = Input.GetAxis("Vertical");
Vector2 Direction = new Vector2(X, Y).normalized; Movement.Direction = new Vector2(X, Y).normalized;
Body.velocity = Direction * MoveSpeed;
Vector3 MousePos = Input.mousePosition; Vector3 MousePos = Input.mousePosition;
Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos); Vector3 PointedPos = Camera.main.ScreenToWorldPoint(MousePos);
@ -95,17 +94,13 @@ namespace Saltosion.OneWeapon {
} }
if (Direction.magnitude > 0.05) { if (Movement.SpeedPercentage > 0.05) {
BodyAnim.SetFloat("Speed", 1);
HeadAnim.SetFloat("Speed", 1);
IsMoving = true; IsMoving = true;
Bobbing.BobbingMultiplier = 1;
} else { } else {
BodyAnim.SetFloat("Speed", 0);
HeadAnim.SetFloat("Speed", 0);
IsMoving = false; IsMoving = false;
Bobbing.BobbingMultiplier = 0;
} }
BodyAnim.SetFloat("Speed", Movement.SpeedPercentage);
HeadAnim.SetFloat("Speed", Movement.SpeedPercentage);
bool Shoot = Input.GetButtonDown("Shoot"); bool Shoot = Input.GetButtonDown("Shoot");
if (Shoot) { if (Shoot) {

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 018a3d1f7d59172409fca8ec15f1c654 guid: 1444582c6b6fb0541bbe54879e9a5012
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.Effects;
namespace Saltosion.OneWeapon.Utils {
public class AcceleratedMovement : MonoBehaviour {
public Rigidbody2D Body;
public Bobbing Bobbing;
private Vector2 LastDirection = Vector2.zero;
public Vector2 Direction = Vector2.zero;
public float MaxSpeed = 50;
public float AccelerationSpeed = 35;
public Vector2 CurrentVelocity { private set; get; }
public float SpeedPercentage { private set; get; }
private float CurrentSpeed = 0;
void Update() {
if (Direction.magnitude > 0) {
CurrentSpeed += AccelerationSpeed * Time.deltaTime;
} else {
CurrentSpeed -= AccelerationSpeed * Time.deltaTime;
}
CurrentSpeed *= 1 - (Vector2.Angle(Direction, LastDirection) / 180);
Debug.Log(1 - (Vector2.Angle(Direction, LastDirection) / 180));
CurrentSpeed = Mathf.Clamp(CurrentSpeed, 0, MaxSpeed);
SpeedPercentage = CurrentSpeed / MaxSpeed;
CurrentVelocity = Direction.normalized * CurrentSpeed;
LastDirection = Direction;
Body.velocity = CurrentVelocity;
Bobbing.BobbingMultiplier = SpeedPercentage;
}
}
}

View File

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

View File

@ -1,6 +1,6 @@
using UnityEngine; using UnityEngine;
namespace Saltosion.OneWeapon { namespace Saltosion.OneWeapon.Utils {
public class Util { public class Util {
public static T GetClosestTo<T>(Transform Searcher, float radius, bool needsLineOfSight = false) where T : MonoBehaviour { public static T GetClosestTo<T>(Transform Searcher, float radius, bool needsLineOfSight = false) where T : MonoBehaviour {
Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(Searcher.position, radius); Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(Searcher.position, radius);