Hello,
I am making a character with a baseball bat. The character is supposed to be moving and swing the bat while doing so.
My setup consists of:
A parent, which is basically the Baseballer with a standard movement code:
void Start () {
rb = GetComponent<Rigidbody> ();
}
void FixedUpdate(){
if (rb.velocity.magnitude < speedLimit)
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
rb.AddForce(movement * speed);
}
}
and a child, which is the bat, with IsKinematic checked, with the following code:
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
//read RIGHT stick inputs
float moveHorizontal = Input.GetAxis("Horizontal2");
float moveVertical = Input.GetAxis("Vertical2");
Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
if (movement != Vector3.zero)
{
rb.MoveRotation(Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), Time.deltaTime * rotateSpeed));
}
}
For some reason, I can only move the bat with the right stick when the baseballer is NOT moving. What could it be? If I untick IsKinematic it works correctly, but I need the bat to be Kinematic.