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}
HandRetractSpeed: 10
HandRotationRetractSpeed: 300
Bobbing: {fileID: 5620918083888341557}
--- !u!114 &5050980832709922958
MonoBehaviour:
m_ObjectHideFlags: 0
@ -548,6 +549,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
BobbedTransform: {fileID: 4562179207922364650}
BobbingMultiplier: 1
BobbingGravity: 0.8
BobbingLaunchSpeed: 0.1
BobbingDirection: {x: 0, y: 1}

View File

@ -2,28 +2,30 @@
using System.Collections.Generic;
using UnityEngine;
public class Bobbing : MonoBehaviour {
namespace Saltosion.OneWeapon.Effects {
public class Bobbing : MonoBehaviour {
public Transform BobbedTransform;
public Transform BobbedTransform;
[Range(0, 1)]
public float BobbingMultiplier = 1;
public float BobbingGravity = 0.5f;
public float BobbingLaunchSpeed = 5f;
public Vector2 BobbingDirection = new Vector2(0, 1);
[Range(0, 1)]
public float BobbingMultiplier = 1;
public float BobbingGravity = 0.5f;
public float BobbingLaunchSpeed = 5f;
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 UnityEngine;
using UnityEngine.Animations;
using Saltosion.OneWeapon.Effects;
namespace Saltosion.OneWeapon {
public class Player : MonoBehaviour {
@ -36,6 +37,8 @@ namespace Saltosion.OneWeapon {
private float CurrentHandRotation = 0f;
private float CurrentHandDistance = 0f;
public Bobbing Bobbing;
public bool IsMoving {
private set; get;
} = false;
@ -96,10 +99,12 @@ namespace Saltosion.OneWeapon {
BodyAnim.SetFloat("Speed", 1);
HeadAnim.SetFloat("Speed", 1);
IsMoving = true;
Bobbing.BobbingMultiplier = 1;
} else {
BodyAnim.SetFloat("Speed", 0);
HeadAnim.SetFloat("Speed", 0);
IsMoving = false;
Bobbing.BobbingMultiplier = 0;
}
bool Shoot = Input.GetButtonDown("Shoot");