rb. MovePosition slowly enters another Collider
Hi! I am new in the Game Dev Community. I am building a little 3D Game where you control a character. He got a Collider, a Rigidbody and a simple rigidbody.MovePosition Script
I want the character to collide with some Objects and have physic applied on both but on some (like walls) i want the character to stand still.
thats the Script:
using UnityEngine;
public class PlayerManager : MonoBehaviour
{
Rigidbody Plyrb;
Vector3 movement;
public float moveSpeed;
public float SprintMult;
void Start()
{
Plyrb = gameObject.GetComponent<Rigidbody>();
}
void Update()
{
Movement();
}
void FixedUpdate()
{
//Slower diagonal speed
if (movement.x > 0 && movement.z > 0)
{
movement /= 1.5f;
Plyrb.MovePosition(Plyrb.position + (movement * moveSpeed * Time.fixedDeltaTime));
}
else
{
Plyrb.MovePosition(Plyrb.position + (movement * moveSpeed * Time.fixedDeltaTime));
}
}
public void Movement()
{
movement = new Vector3 (Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
}
if (Input.GetKeyDown(KeyCode.LeftShift))
{
moveSpeed *= SprintMult;
}
if (Input.GetKeyUp(KeyCode.LeftShift))
{
moveSpeed /= SprintMult;
}
}
Now the main Problem: when the player hits another collider and I still press the Movement-Key, he starts entering it slowly, until it reaches the center of the other object. Then he gets fired out of the Collider.
If i reduce the speed it doesnt happen, but then i am way to slow to call it real movement. (for real its really slow)
I also tried using Continuous Collision Detection but it doesnt changed anything.
I also used the "DontGoThroughtThings" Script but it doesnt changed anything eather.
Making the Character kinematic makes him move throught stuff without slowly down and thats also not what i want.
Maybe someone knows whats up or got a other code that fits my needs. :D
Happy coding to all of you :D