Make player control the bobbing properly

This commit is contained in:
Sofia 2019-08-07 22:43:22 +03:00
parent c28f71118f
commit 4898d2c435
3 changed files with 27 additions and 18 deletions

View File

@ -512,6 +512,7 @@ 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
@ -548,6 +549,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
BobbedTransform: {fileID: 4562179207922364650} BobbedTransform: {fileID: 4562179207922364650}
BobbingMultiplier: 1
BobbingGravity: 0.8 BobbingGravity: 0.8
BobbingLaunchSpeed: 0.1 BobbingLaunchSpeed: 0.1
BobbingDirection: {x: 0, y: 1} BobbingDirection: {x: 0, y: 1}

View File

@ -2,28 +2,30 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class Bobbing : MonoBehaviour { namespace Saltosion.OneWeapon.Effects {
public class Bobbing : MonoBehaviour {
public Transform BobbedTransform; public Transform BobbedTransform;
[Range(0, 1)] [Range(0, 1)]
public float BobbingMultiplier = 1; public float BobbingMultiplier = 1;
public float BobbingGravity = 0.5f; public float BobbingGravity = 0.5f;
public float BobbingLaunchSpeed = 5f; public float BobbingLaunchSpeed = 5f;
public Vector2 BobbingDirection = new Vector2(0, 1); public Vector2 BobbingDirection = new Vector2(0, 1);
private float BobbingSpeed; private float BobbingSpeed;
private float CurrentBobbingState = 0; private float CurrentBobbingState = 0;
void Update() {
BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime);
if (CurrentBobbingState <= 0) {
BobbingSpeed = (BobbingLaunchSpeed / 10);
}
CurrentBobbingState += BobbingSpeed;
BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier;
void Update() {
BobbingSpeed -= (BobbingGravity / 10 * Time.deltaTime);
if (CurrentBobbingState <= 0) {
BobbingSpeed = (BobbingLaunchSpeed / 10);
} }
CurrentBobbingState += BobbingSpeed;
BobbedTransform.localPosition = BobbingDirection * CurrentBobbingState * BobbingMultiplier;
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Animations; using UnityEngine.Animations;
using Saltosion.OneWeapon.Effects;
namespace Saltosion.OneWeapon { namespace Saltosion.OneWeapon {
public class Player : MonoBehaviour { public class Player : MonoBehaviour {
@ -36,6 +37,8 @@ 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;
} = false; } = false;
@ -96,10 +99,12 @@ namespace Saltosion.OneWeapon {
BodyAnim.SetFloat("Speed", 1); BodyAnim.SetFloat("Speed", 1);
HeadAnim.SetFloat("Speed", 1); HeadAnim.SetFloat("Speed", 1);
IsMoving = true; IsMoving = true;
Bobbing.BobbingMultiplier = 1;
} else { } else {
BodyAnim.SetFloat("Speed", 0); BodyAnim.SetFloat("Speed", 0);
HeadAnim.SetFloat("Speed", 0); HeadAnim.SetFloat("Speed", 0);
IsMoving = false; IsMoving = false;
Bobbing.BobbingMultiplier = 0;
} }
bool Shoot = Input.GetButtonDown("Shoot"); bool Shoot = Input.GetButtonDown("Shoot");