Bolt - state.Animator dont work
Options
Hi, i started use bolt to create a online shooter. First i get the deltaPosition from the animator and set this to characterController.Move. With animator.setFloat its work but its not synchronized. i search a little bit and found a page about animation where its described how to handle that. i tried to use state.Animator("XXX", inputY) but then become totally weird. I must hold the walk key more than 5 secnds. till they react and if they start to run they dont stop for the first 5-6 secnds.
Heres my Code i changed it more times but i didnt find any solution. at the and i tried to applyrootmotion directly (not trough the move function from charactercontroller) but the same..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Bolt;
using UdpKit;
public class PlayerMovement : EntityBehaviour<IPlayerOnline>
{
private Camera player_cam;
private Animator animator;
private CharacterController c_controller;
public float moveSmoothness = 0.1f;
public float turnSmoothness;
private Vector3 deltaPos = Vector3.zero;
private Vector3 velocity;
private float gravity = -9.81f;
private float inputX;
private float inputY;
public override void Attached()
{
if (entity.IsOwner)
{
player_cam = Camera.main;
c_controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
state.SetTransforms(state.Transform, transform);
state.SetAnimator(animator);
state.Animator.applyRootMotion = entity.IsOwner;
}
// Update is called once per frame
public override void SimulateOwner()
{
inputX = Input.GetAxis("Horizontal");
inputY = Input.GetAxis("Vertical");
// animator.SetFloat("BlendX", inputX, moveSmoothness,Time.deltaTime);
//animator.SetFloat("BlendY", inputY, moveSmoothness, Time.deltaTime);
state.BlendX = inputX;
state.BlendY = inputY;
// Move();
}
void Move()
{
if (c_controller.isGrounded && velocity.y < 0)
velocity.y = 0;
velocity.y += gravity * BoltNetwork.FrameDeltaTime;
#region Rotate Player
Vector3 camRot = new Vector3(transform.eulerAngles.x, player_cam.transform.eulerAngles.y, transform.eulerAngles.z);
Quaternion rot = Quaternion.Euler(camRot);
transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime / turnSmoothness);
#endregion
}
private void OnAnimatorMove()
{
animator.ApplyBuiltinRootMotion();
// deltaPos = animator.deltaPosition;
// c_controller.Move(deltaPos);
//c_controller.Move(velocity * BoltNetwork.FrameDeltaTime);
}
}
Heres my Code i changed it more times but i didnt find any solution. at the and i tried to applyrootmotion directly (not trough the move function from charactercontroller) but the same..
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Bolt;
using UdpKit;
public class PlayerMovement : EntityBehaviour<IPlayerOnline>
{
private Camera player_cam;
private Animator animator;
private CharacterController c_controller;
public float moveSmoothness = 0.1f;
public float turnSmoothness;
private Vector3 deltaPos = Vector3.zero;
private Vector3 velocity;
private float gravity = -9.81f;
private float inputX;
private float inputY;
public override void Attached()
{
if (entity.IsOwner)
{
player_cam = Camera.main;
c_controller = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
state.SetTransforms(state.Transform, transform);
state.SetAnimator(animator);
state.Animator.applyRootMotion = entity.IsOwner;
}
// Update is called once per frame
public override void SimulateOwner()
{
inputX = Input.GetAxis("Horizontal");
inputY = Input.GetAxis("Vertical");
// animator.SetFloat("BlendX", inputX, moveSmoothness,Time.deltaTime);
//animator.SetFloat("BlendY", inputY, moveSmoothness, Time.deltaTime);
state.BlendX = inputX;
state.BlendY = inputY;
// Move();
}
void Move()
{
if (c_controller.isGrounded && velocity.y < 0)
velocity.y = 0;
velocity.y += gravity * BoltNetwork.FrameDeltaTime;
#region Rotate Player
Vector3 camRot = new Vector3(transform.eulerAngles.x, player_cam.transform.eulerAngles.y, transform.eulerAngles.z);
Quaternion rot = Quaternion.Euler(camRot);
transform.rotation = Quaternion.Lerp(transform.rotation, rot, Time.deltaTime / turnSmoothness);
#endregion
}
private void OnAnimatorMove()
{
animator.ApplyBuiltinRootMotion();
// deltaPos = animator.deltaPosition;
// c_controller.Move(deltaPos);
//c_controller.Move(velocity * BoltNetwork.FrameDeltaTime);
}
}
0
Comments
-
I think the problem was that i had script only build checked in the build options0