I’m a noob so go easy on me.
I’m trying to make a simple jump function. Unfortunately, I go up very quickly and come down very slowly. Code is this:
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0F, moveVertical);
//Note I'm not adding anything to the y vector here ^
rb.velocity = movement * speed;
if (Input.GetKey("space") && detectGround())
{
rb.AddForce(0.0F, 1000, 0.0F);
//It seems like I'm adding way too much force on y vector, but even with that much I barely leave the ground. I need, like, 10,000 to get a good high jump.
}
}
bool detectGround()
{
Vector3 down = transform.TransformDirection(Vector3.down);
return Physics.Raycast(transform.position, down, .51F);
}
I’m aware that I might run into weird gravity problems if I’m using odd scales, but I’m dealing with a 1x1x1 sphere in this case. Drag is also not the problem (and if it was, why do I go up so fast?). I’ve also tried adding some weight to my gravity by changing my y vector. That makes me fall faster but doesn’t help the jump any.
Interestingly, I don’t seem to have this problem if I use rb.AddForce(movementspeed) instead of rb.velocity = movementspeed. Then, however, I don’t get the tight control that I want for my X axis and Z axis. (I accelerate too slowly, never hit a peak speed, and have trouble stopping).
How do I fix this?