I’m trying out using a Rigidbody for my game characters rather than Character Controllers because it seems I have easier options for what I’m doing later. Anyway, I’m using rigidBody.AddForce(moveDirection) where the moveDirection comes from the horizontal and vertical inputs to move the character around the screen. The problem is, that when I fall off of an edge, gravity stops working when I let go of the controls. The character falls while moving, but not while standing still. I can’t figure it out. Project Gravity is set to -9.81 on the Y axis. Character’s Mass is 2. Drag is 0. Angular Drag is 0.05
The other thing that I don’t understand is that I have to shrink him down all the way until my scale under transform is around 0.2 just for him to fall at all even with my issue. The model was made with MakeHuman and Blender and the scale factor on the import is 1.
Code for the movement is:
using UnityEngine;
using System.Collections;
public class WeightLifterDudeMovement : MonoBehaviour {
Rigidbody rigidBody;
Animator anim;
bool allowMovement;
public float moveSpeed = 10f;
Vector3 moveDirection;
void Start () {
rigidBody = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void Update()
{
GetInput();
rigidBody.transform.LookAt(transform.position + moveDirection);
rigidBody.AddForce(moveDirection);
//rigidBody.velocity = moveDirection;
}
void GetInput()
{
float hMovement = Input.GetAxis("Horizontal");
float vMovement = Input.GetAxis("Vertical");
moveDirection = new Vector3(hMovement * moveSpeed, 0.0f, vMovement * moveSpeed);
if (moveDirection != Vector3.zero)
{
anim.SetBool("isWalking", true);
}
else
{
anim.SetBool("isWalking", false);
}
}
}
And this is the result of things so far.
https://www.youtube.com/watch?v=oZurrJ_8tCI
Can someone point me in the right direction? Thanks.