Hey all,
I already looked through the forum but couldn't find the right solution for my issue with my player movement.
If I hit play, my player capsule moves correctly in the beginning but after a while (10-60sec) and more wasd input the capsule starts spinning around the y-axes(the other axes are frozen under the rigidbody constraints) and changes position slowly, without any keyboard input.
I checked the input manager(working with macOS 12.6.1 and MacBook pro-2015), gravity and dead options, but that did not help. My Script is attached.
I would really appreciate it if someone could help me find the solution.
best, jakob
unity version 2020.3.26f1
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CapsulePlayerScript : MonoBehaviour
{
public float turnSpeed = 20f;
public float m_Speed = 0.5f;
Rigidbody m_Rigidbody;
Quaternion m_Rotation = Quaternion.identity;
private GameMaster gm;
void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
gm = GameObject.FindGameObjectWithTag("GM").GetComponent<GameMaster>();
transform.position = gm.lastCheckPointPos;
}
void FixedUpdate()
{
//Movement
Vector3 m_Input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
m_Input.Normalize();
m_Rigidbody.MovePosition(transform.position + m_Input * m_Speed * Time.fixedDeltaTime);
//Rotation
Vector3 desiredForward = Vector3.RotateTowards (transform.forward, m_Input, turnSpeed * Time.deltaTime, 0f);
m_Rotation = Quaternion.LookRotation (desiredForward);
m_Rigidbody.MoveRotation(m_Rotation);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}