I have a problem with my project. My character is falling down veeeery slowly, Y is -1 like every 10 seconds. The character has attached a rigidbody. His mass is 1. gravity checked, kinematic unchecked. moving around with rigidbody.velocity works just fine. in the settings, gravity force is set to -9.81. Time scale is 1. the animator has apply root motion unchecked. Yet it won’t work, no matter what I do. Here is the script:\
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
Rigidbody rb;
public float movementSpeed;
public float rotationSpeed;
Vector3 lookAtVector;
private float g = 9.81f;
private float mass;
Animator anim;
public Transform cam;
void Start() {
lookAtVector = transform.position;
rb = GetComponent<Rigidbody>();
rb.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
anim = GetComponent<Animator>();
mass = rb.mass;
}
void FixedUpdate() {
print(transform.position);
RaycastHit hit;
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
{
print(hit.point);
Debug.DrawLine(transform.position, hit.point, Color.cyan);
}
if(hit.point.y != transform.position.y)
{
rb.constraints = rb.constraints | RigidbodyConstraints.FreezeRotationY;
}
else
{
rb.constraints &= ~RigidbodyConstraints.FreezePositionY;
}
Move();
}
public void Move()
{
float z = 0;
float x = 0;
z = Input.GetAxis("Horizontal");
x = Input.GetAxis("Vertical");
//rb.AddForce(new Vector3(0, -1, 0)*g*mass);
if (z != 0 || x != 0)
{
Vector3 direction = new Vector3(x * cam.rotation.x, 0, z * cam.rotation.z);
Vector3 destination = direction + transform.position;
lookAtVector = transform.position + direction;
//rb.MovePosition(transform.position + transform.forward * Time.deltaTime);
rb.velocity = direction * movementSpeed;
anim.SetFloat("Blend", 1f);
}
else
{
lookAtVector = transform.position;
rb.velocity = Vector3.zero;
anim.SetFloat("Blend", 0);
}
if(lookAtVector != null)
transform.LookAt(lookAtVector);
}
}