Advertisement
Guest User

Character

a guest
Feb 16th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Bolt;
  5.  
  6. public class Character : Bolt.EntityEventListener<IPlayerState>
  7. {
  8.     private CharacterController controller;
  9.  
  10.     [SerializeField]
  11.     private CharacterMotor motor;
  12.  
  13.     Vector3 movement;
  14.  
  15.     private void Start()
  16.     {
  17.         controller = GetComponent<CharacterController>();
  18.         motor = GetComponent<CharacterMotor>();
  19.     }
  20.  
  21.     public override void Attached()
  22.     {
  23.         state.SetTransforms(state.PlayerTransform, transform);
  24.     }
  25.  
  26.     public override void SimulateController()
  27.     {
  28.         IPlayerCommandInput input = PlayerCommand.Create();
  29.  
  30.         input.horizontal = Input.GetAxis("Horizontal");
  31.         input.vertical = Input.GetAxis("Vertical");
  32.         input.jump = Input.GetKey(KeyCode.Space);
  33.  
  34.         entity.QueueInput(input);
  35.     }
  36.  
  37.     public override void ExecuteCommand(Command command, bool resetState)
  38.     {
  39.         PlayerCommand cmd = (PlayerCommand)command;
  40.  
  41.         if(resetState)
  42.         {
  43.             motor.SetState(cmd.Result.position, cmd.Result.localposition, cmd.Result.velocity, cmd.Result.grounded);
  44.         }
  45.         else
  46.         {
  47.             var result = motor.Move(cmd.Input.horizontal, cmd.Input.vertical);
  48.  
  49.             cmd.Result.localposition = result.localPosition;
  50.             cmd.Result.position = result.position;
  51.             cmd.Result.velocity = result.velocity;
  52.             cmd.Result.grounded = result.isGrounded;
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement