- Home /
Why does my character fall slowly even though rigid.drag = 0?
https://www.youtube.com/watch?v=F-bwle2BPiA&feature=youtu.be
The video above says all.
Here is the following code I used if you cannot see the video in HD yet:
public class CameraManager : MonoBehaviour
{
public float followSpeed;
public Transform target;
public Transform cam;
public static CameraManager singleton;
void Awake()
{
singleton = this;
}
public void Init(Transform t)
{
target = t;
cam = Camera.main.transform;
}
public void FixedTick(float d)
{
FollowTarget (d);
}
void FollowTarget(float d)
{
Vector3 targetPosition = Vector3.Lerp (transform.position, target.position, d * followSpeed);
transform.position = targetPosition;
}
}
public class InputManager : MonoBehaviour
{
public float horizontal;
CameraManager cam;
StatesManager states;
[HideInInspector]
public float delta;
void Start ()
{
cam = CameraManager.singleton;
states = GetComponent<StatesManager> ();
states.Init();
cam.Init(this.transform);
}
void FixedUpdate()
{
delta = Time.fixedDeltaTime;
GetInput ();
UpdateStates ();
states.FixedTick (delta);
cam.FixedTick (delta);
}
void Update ()
{
delta = Time.deltaTime;
}
void GetInput()
{
horizontal = Input.GetAxis ("Horizontal");
}
void UpdateStates()
{
states.horizontal = horizontal;
states.moveDir = new Vector3 (horizontal, 0, 0);
states.moveAmount = horizontal;
states.moveAmount = Mathf.Abs (states.moveAmount);
}
}
public class StatesManager : MonoBehaviour
{
[Header ("Initialization")]
public GameObject activeModel;
[Header ("Inputs")]
public float horizontal;
public float moveAmount;
public Vector3 moveDir;
[Header ("Stats")]
public float moveSpeed;
public float dashSpeed;
public float rotateSpeed;
[Header ("States")]
public bool onGround;
public bool inAction;
public bool canMove;
public bool dashing;
public bool jumping;
[HideInInspector]
public Animator anim;
[HideInInspector]
public Rigidbody rigid;
public void Init ()
{
SetUpAnim ();
SetUpRigid ();
}
public void FixedTick(float d)
{
HandleMovementAndRotations (d);
HandleAnims (d);
}
public void Tick (float d)
{
}
void HandleAnims(float d)
{
anim.SetFloat ("vertical", moveAmount, 0.1f, d);
}
void HandleMovementAndRotations(float d)
{
rigid.drag = (moveAmount > 0 || onGround == false) ? 0 : 4;
rigid.velocity = moveDir * (moveSpeed * moveAmount);
if (moveDir == Vector3.zero)
moveDir = Vector3.forward;
Quaternion tr = Quaternion.LookRotation (moveDir);
Quaternion targetRotation = Quaternion.Slerp (transform.rotation, tr, d * moveAmount * rotateSpeed);
transform.rotation = targetRotation;
}
void SetUpAnim()
{
if (activeModel == null) {
anim = GetComponentInChildren<Animator> ();
if (anim == null)
{
Debug.Log ("No model found.");
}
else
{
activeModel = anim.gameObject;
}
}
if (anim == null)
anim = activeModel.GetComponent<Animator> ();
anim.applyRootMotion = false;
}
void SetUpRigid()
{
rigid = GetComponent<Rigidbody> ();
rigid.angularDrag = 999;
rigid.drag = 4;
rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
}
}
And yes, the gravity is at it's default -9.81 setting, but I'd like to avoid messing with that option since it might complicate things down the road.
pls help me. ive tried for a week. im desperate. thank you.
Answer by LT23Live · Aug 23, 2017 at 09:22 PM
Your states manager sets your drag to 4.
A lower drag means less resistance to the weight pushing it down.
if you want your character not to drop any try considering one of the three things.
Remove Rigid Body and Use Transform.Translate
Increase the drag to 10000
Disable 'Use Gravity' on the rigid body.
An object with a drag of 4 doesn't fall that slowly, and the states manager sets the drag to 0 if bool onGround = false (and the video didn't show it, but onGround was false in the video).
I know, I want the object to fall faster
I want the character to drop faster.
Your answer
Follow this Question
Related Questions
Where is the general Rigidbodies Drag? 3 Answers
Wrong gravity calculation? 2 Answers
Gliding vs bad acceleration dilema 0 Answers
Gravity suddenly started working very slowly 1 Answer
Instantiated prefab changes gravitational speed when dragged? 0 Answers