# Rigidbody y velocity is stuck on 0, gravity is not turned off.

Greetings, I’ve come across a pretty serious problem, the rigidbody player falls at an impossibly slow speed when close to the ground, the fault is of this code:

``````	Vector3 forwardVel = movementBase.transform.forward * speed * moveVertical;
Vector3 horizontalVel = movementBase.transform.right * speed * moveHorizontal;

if(Physics.Raycast(transform.position, -Vector3.up, out hit, distanceToGround + 0.1f))
{
if (hit.collider.rigidbody)
{
isGrounded = true;

rigidbody.velocity = forwardVel + horizontalVel + hit.collider.rigidbody.velocity;
}
else
{
isGrounded = true;

rigidbody.velocity = forwardVel + horizontalVel;
}
}
else
{
isGrounded = false;

var yVel = rigidbody.velocity;
yVel.y = rigidbody.velocity.y;

rigidbody.velocity = forwardVel / 20 + horizontalVel / 20 + yVel;
}
``````

Sadly, I can’t find a way to fix this, the issue is that when the ray hits the ground, I set the velocity, this is necessary for the game to work, my solution of setting the yVel in midair doesn’t work with the ground because if this happens, then any velocity settings are just accelerated far too much, I suspect this is because the yVel starts out from rigidbody.velocity, which results in just adding more and more velocity over time.

How can I fix this?, all the code here is in FixedUpdate.

Assuming you’re calling this code every frame in FixedUpdate(), you’re setting the rigidbody.velocity to be a sum of two Vector3s - forwardVel and horizontalVel - neither of which have a y component. Without a y component to a rigidbody’s velocity, it won’t fall.

Hi dude! LIKE MY answer >

``````	using UnityEngine;
using System.Collections;

public class AddSpeedRigidBody : MonoBehaviour {

public float speed = 10.0F;
public float rotationSpeed = 100.0F;

void Update() {
float moveVertical = Input.GetAxis("Vertical") * speed;
float moveHorizontal = Input.GetAxis("Horizontal") * rotationSpeed;
moveVertical *= Time.deltaTime;
moveHorizontal *= Time.deltaTime;
transform.Translate(0, 0, moveVertical);
transform.Rotate(0, moveHorizontal, 0);

}
}
``````