blob: dcd96a0ad7d804bcb6e0baf77bc1bd4c43c8f555 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using Rigging.Data;
using Rigging.Inputs;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Rigging.Action
{
public class Movement : RiggingActionBase
{
private InputHandler inputHandler;
public float friction = 0.9f;
public Vector3 movementVector;
public AnimationParam<float> forceAmounts;
private RigidbodyHolder allRigs;
public AnimationCurve jumpCurve;
public float jumpForce;
private StandingDataHandler standingData;
private MovementDataHandler data;
[HideInInspector, NonSerialized]
public float multiplier = 1f;
protected override void OnStart()
{
forceAmounts.SetPlayer(player);
standingData = player.status.standingData;
inputHandler = player.input;
allRigs = player.status.body;
data = player.status.movementData;
}
private void FixedUpdate()
{
data.sinceJump += Time.fixedDeltaTime;
movementVector += inputHandler.inputMovementDirection * forceAmounts.current;
movementVector *= friction;
allRigs.AddForceToAll(movementVector * multiplier, ForceMode.Acceleration);
}
public void Jump()
{
if (!(data.sinceJump < 0.5f) && !(standingData.sinceGrounded > 0.3f))
{
data.sinceJump = 0f;
StartCoroutine(AddJumpForce());
}
}
private IEnumerator AddJumpForce()
{
float counter = 0f;
allRigs.ModifyVelocityForEach((_rig) => { return new Vector3(_rig.velocity.x, 0f, _rig.velocity.z); });
while (counter < jumpCurve.keys[jumpCurve.length - 1].time)
{
counter += Time.deltaTime;
allRigs.AddForceToAll(Vector3.up * multiplier * jumpForce * jumpCurve.Evaluate(counter) * Time.deltaTime, ForceMode.Acceleration);
yield return null;
}
}
}
}
|