Advertisement
Guest User

xafasggas

a guest
Feb 15th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 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.     private void Start()
  14.     {
  15.         controller = GetComponent<CharacterController>();
  16.         motor = GetComponent<CharacterMotor>();
  17.         //motor = new CharacterMotor(motor, controller, transform);    
  18.     }
  19.  
  20.     public override void Attached()
  21.     {
  22.         state.SetTransforms(state.PlayerTransform, transform);
  23.     }
  24.  
  25.     public override void SimulateController()
  26.     {
  27.         IPlayerCommandInput input = PlayerCommand.Create();
  28.  
  29.         input.horizontal = Input.GetAxis("Horizontal");
  30.         input.vertical = Input.GetAxis("Vertical");
  31.         input.jump = Input.GetKey(KeyCode.Space);
  32.  
  33.         entity.QueueInput(input);
  34.     }
  35.  
  36.     public override void ExecuteCommand(Command command, bool resetState)
  37.     {
  38.         PlayerCommand cmd = (PlayerCommand)command;
  39.  
  40.         if(resetState)
  41.         {
  42.             motor.MoveLocal(cmd.Result.velocity);
  43.         }
  44.         else
  45.         {
  46.             motor.Move(cmd.Input.horizontal, cmd.Input.vertical, cmd.Input.jump);
  47.  
  48.             cmd.Result.position = transform.position;
  49.             cmd.Result.velocity = motor.movement;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement