Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- [RequireComponent(typeof (CapsuleCollider))]
- [RequireComponent(typeof (Grounding))]
- [RequireComponent(typeof (Rigidbody))]
- public class Actor : MonoBehaviour {
- [Header("Parameters")]
- public float ForwardSpeed;
- public float LateralSpeed;
- public float BackwardSpeed;
- [Header("Controls")]
- public bool Controller;
- public KeyboardMap KeyboardBindings;
- public ControllerMap ControllerBindings;
- [Header("Abilities")]
- public Ability PrimaryAbility = new Ability();
- public Ability SecondaryAbility = new Ability();
- public Ability SpecialAbility1 = new Ability();
- public Ability SpecialAbility2 = new Ability();
- public Ability SpecialAbility3 = new Ability();
- public Ability MiscellaneousAbility = new Ability();
- private Animator animator_;
- private Grounding grounding_;
- private Rigidbody body_;
- protected void Start() {
- animator_ = GetComponent<Animator>();
- grounding_ = GetComponent<Grounding>();
- body_ = GetComponent<Rigidbody>();
- }
- public virtual void MoveForward() {
- body_.MovePosition(transform.position + transform.forward * ForwardSpeed);
- }
- public virtual void MoveBackward() {
- body_.MovePosition(transform.position - transform.forward * BackwardSpeed);
- }
- public virtual void MoveLeft() {
- body_.MovePosition(transform.position - transform.right * LateralSpeed);
- }
- public virtual void MoveRight() {
- body_.MovePosition(transform.position + transform.right * LateralSpeed);
- }
- public virtual void Jump() {
- if (grounding_.Grounded) {
- body_.AddForce(transform.up * 5, ForceMode.Impulse);
- }
- }
- }
- // Grounding class for enabling/disabling jump. Somewhat buggy :,(
- using UnityEngine;
- [RequireComponent(typeof(BoxCollider))]
- public class Grounding : MonoBehaviour {
- public BoxCollider Region;
- public bool Grounded { get; private set; }
- protected void FixedUpdate() {
- Grounded = false;
- }
- // TODO : Layer-based implementation.
- protected void OnTriggerStay(Collider other) {
- Grounded = other.gameObject != gameObject;
- }
- }
- // TODO : @Mopzilla
- // Add velocity to Actor. You'll want it to increase on Update if you're moving forward and decrease if you're not. Use the velocity to scale body_.MovePosition's argument.
- // Make sure you keep current velocity and velocity from last frame.
- // When you send your guy into ragdoll mode, do this:
- // acceleration = (this frame's velocity - last frame's velocity) / time.DeltaTime
- // body_.AddForce(mass of force * acceleration, ForceMode.Impulse);
- // There are a lot of ways you could do velocity, like sampling a curve, using lerp, etc. I'll leave that for you to experiment.
- // To add turning, in the move left/right functions instead of doing what I did by moving their position due west/east, you would continue to move your character forward and a little bit to the left/right.
- // You can get really creative with turning by using Lerp and a smoothing function to make him turn a little bit, then gradually more, for realism.
- // Message me if you need any help!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement