Hunter & Tiff Eidmann

Character falls over when AddForce is applied.

I have a character in my game which has a box collider around it and has a rigidbody applied. I applied the below code to the character and it just falls over like a domino. Below is the script and a screen shot of all the characters components (Also note that I brought this character in from medium and because of the weird angle he was dragged in at I had to reposition him thus changing in local axis and why the force is applied to up rather than forward)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SphereMove : MonoBehaviour {
Rigidbody harV;
void Start()
harV = GetComponent<Rigidbody>();

void FixedUpdate()
if (Input.GetKey(KeyCode.X))
harV.AddForce(transform.forward * 50);
Debug.Log("Force Applied");

If I apply the force to forward (which actually makes it go up because of the skewed local axis) it works fine. Does anyone know what is wrong here or have a tutorial they could point me to for creating character controls for something other than a ball? Thanks everyone!

  • crew

    The image is a bit tough to see, I think you have rotation for the rigidbody along the X and Z frozen correct? When you say he falls over, is he rotating at all? Is the entire character hierarchy falling down or is it just portions of it? I would have to see the fallen state to know more. 

    Are you creating a third person character? I would take a look at the rigidbody controller in the Characters package as it has everything you're trying to create it looks like (you can adjust the camera placement). You can modify it or at least get an idea of what the issue might be.