0
\$\begingroup\$

enter image description hereso My problem is a bit weird. I have a model that will not fall at the correct speed. She falls incredibly slowly. This is the only script attached to her, and I did the "Scale to large" test by placing a box next to her and letting them drop at the same time. The box fell instantly to the ground and she just kind floats taking her time.

Gravity is on kinematic is off, I'm out of ideas and could use some help. :D!

Thank you.

This is unity in c#.

using UnityEngine;

using System.Collections;

public class PlayerController : MonoBehaviour {

// public variables
public float speed = 1.5f;
public float JumpH = 1.5f;
public float RotateSpeed = 30f;


//pivate component checks
private Animator animr;
private Rigidbody LillyRB;

//private generic bits.
private bool checker;
private float movever;
private float movehor;
private float turn;



void Start (){
    LillyRB = GetComponent<Rigidbody> ();
    animr = GetComponent<Animator> ();

}

void FixedUpdate () {

    // movevertical and move horizontal check for player input wasd
    // jump checks for jump/spacebar.




    movever = Input.GetAxisRaw ("Vertical");
    movehor = Input.GetAxisRaw ("Horizontal");
    turn = Input.GetAxisRaw ("mouse x");
    Quaternion rot = LillyRB.rotation;

    Quaternion Exturn = Quaternion.Euler (0.0f, RotateSpeed * Time.deltaTime *  turn + rot.eulerAngles.y, 0.0f);


    if (movehor != 0 || movever != 0) {
        checker = true;
    } 
    else {
        checker = false;
    }

    animr.SetBool ("IsMoving", checker);
    LillyRB.MoveRotation (Exturn);
    LillyRB.MovePosition (LillyRB.position + (transform.forward * movever));
    LillyRB.MovePosition (LillyRB.position + (transform.right * movehor));







}

}

\$\endgroup\$
  • \$\begingroup\$ Can you post screenshot of rigid body settings from inspector? \$\endgroup\$ – SanSolo Jun 13 '15 at 1:53
  • \$\begingroup\$ I put it up there. \$\endgroup\$ – Matt A. Draft Jun 13 '15 at 2:05
  • \$\begingroup\$ Dmgregory's answer is right. Those lines move the object from position to position. Gravity has no effect on that. If you want to move it with gravity affecting, set velocity instead of position. Or use AddForce. \$\endgroup\$ – SanSolo Jun 13 '15 at 5:27
  • 1
    \$\begingroup\$ Careful, @SanSolo: setting velocity often creates a similar problem, because it can cancel out any downward acceleration the object has experienced from previous frames - so every frame of its fall is like the first (very slow). We'll typically want to add to the current velocity, rather than replace it completely. \$\endgroup\$ – DMGregory Jun 13 '15 at 14:46
  • \$\begingroup\$ @DMGregory yes, good point. But, unlike manipulating position, resetting velocity is not completely free from gravitational pull. Can be verified by changing gravity values in project settings. \$\endgroup\$ – SanSolo Jun 14 '15 at 14:57
2
\$\begingroup\$

It looks like these two lines are overriding the velocity-based movement from the RigidBody:

LillyRB.MovePosition (LillyRB.position + (transform.forward * movever));
LillyRB.MovePosition (LillyRB.position + (transform.right * movehor));

Generally when combining player/AI control with Rigidbody physics, you'll want to use forces & accelerations to move your character, rather than wrenching position & velocity control away from the physics system - otherwise you take away its ability to handle things like gravity and collisions consistently.

\$\endgroup\$
  • \$\begingroup\$ Thank you, this turned out not to be correct. The animators "apply root motion" was the culprit. That being said, reworking all my movement controls in terms of forces saved me a lot of trouble when I got past this point. Thank you very much. \$\endgroup\$ – Matt A. Draft Jun 15 '15 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.