Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using Bolt;
- public class Character : Bolt.EntityEventListener<IPlayerState>
- {
- private CharacterController controller;
- [SerializeField]
- private CharacterMotor motor;
- Vector3 movement;
- private void Start()
- {
- controller = GetComponent<CharacterController>();
- motor = GetComponent<CharacterMotor>();
- }
- public override void Attached()
- {
- state.SetTransforms(state.PlayerTransform, transform);
- }
- public override void SimulateController()
- {
- IPlayerCommandInput input = PlayerCommand.Create();
- input.horizontal = Input.GetAxis("Horizontal");
- input.vertical = Input.GetAxis("Vertical");
- input.jump = Input.GetKey(KeyCode.Space);
- entity.QueueInput(input);
- }
- public override void ExecuteCommand(Command command, bool resetState)
- {
- PlayerCommand cmd = (PlayerCommand)command;
- if(resetState)
- {
- motor.SetState(cmd.Result.position, cmd.Result.localposition, cmd.Result.velocity, cmd.Result.grounded);
- }
- else
- {
- var result = motor.Move(cmd.Input.horizontal, cmd.Input.vertical);
- cmd.Result.localposition = result.localPosition;
- cmd.Result.position = result.position;
- cmd.Result.velocity = result.velocity;
- cmd.Result.grounded = result.isGrounded;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement