Hello.
I have a GameObject that has kinematic rigidbody, and its movement is being handled by MovePosition
method.
I use kinematic rigidbody because in future this GameObject will have a lot of animations and does not require physics.
However, I want add obstacles into my scene and they are just some 3D models with colliders. Because my GameObject is kinematic, it will just pass through them.
Is there any methods to imitate obstacles that prevents kinematic GameObject pass through them?
private float GetNewDirectionRatio (Vector3 newDirection)
{
float angle = Vector3.Angle (newDirection, lastMovementDirection);
float ratio = 1.0f - angle / 180.0f;
return ratio;
}
private void RotatePlayer(Vector3 newDirection)
{
Vector3 newRotation = Vector3.Lerp (body.transform.forward, newDirection, turnRate * Time.deltaTime);
body.transform.rotation = Quaternion.LookRotation(newRotation);
}
protected void NewMovement(Vector3 movementDirection)
{
// Calculating speed according to the new direction
movementDirection.Normalize ();
currentSpeed = currentSpeed * GetNewDirectionRatio (movementDirection) + acceleration;
currentSpeed = Mathf.Min (currentSpeed, maxMovementSpeed);
// Applying new movement
movementDirection *= currentSpeed * Time.deltaTime;
playersRoot.MovePosition(transform.position + movementDirection);
lastMovementDirection = movementDirection;
RotatePlayer (movementDirection);
}
The method NewMovement
will be called inside update depending on Input value.
Is it possible to imitate collision?