- Home /
Rigidbody falling very slow
I added a rigidbody to my tank player, but now, even when I disable the moving script, the rigidbody falls SYRUP slow. What is happening?
(Here is the code that I commented out)
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { public float moveSpeed; public float turnSpeed; public float shootForce;
public float TurretRotateSpeed;
public Transform turret;
[Header("Bullet")]
public float bulletSpeed;
public Transform shootPoint;
public GameObject bullet;
public float timeBetweenShots = 1f;
public Vector3 shootForceOffset;
private AudioSource shot;
//Movement
private float MovementInputValue;
private float TurnInputValue;
private float turretRotation;
private Rigidbody rb;
private bool canShoot = true;
void Awake()
{
shot = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody>();
}
void Update()
{
//Get Axises
MovementInputValue = Input.GetAxis("Vertical");
TurnInputValue = Input.GetAxis("Horizontal");
//Rotate the Turret
turretRotation += Input.GetAxis("TurretRotate");
Vector3 turretDirection = new Vector3(0, turretRotation,0);
turret.localEulerAngles = turretDirection;
//Move The Tank
Move();
Turn();
if(Input.GetKeyDown(KeyCode.Space) && canShoot)
{
StartCoroutine(Shoot());
}
}
private void Move()
{
Vector3 movement = transform.forward * MovementInputValue * moveSpeed * Time.deltaTime;
Vector3 finishedMovement = rb.position + movement;
transform.position = new Vector3(finishedMovement.x, transform.position.y, finishedMovement.z);
}
private void Turn()
{
float turn = TurnInputValue * turnSpeed * Time.deltaTime;
Quaternion turnRotation = Quaternion.Euler(transform.rotation.x, turn, transform.rotation.z);
rb.MoveRotation(rb.rotation * turnRotation);
}
private IEnumerator Shoot()
{
shot.Play();
canShoot = false;
GameObject Bullet = Instantiate(bullet, shootPoint.position, shootPoint.rotation) as GameObject;
Bullet.transform.rotation = shootPoint.rotation;
Bullet.GetComponent<Rigidbody>().AddForce(Bullet.transform.forward * bulletSpeed);
if (shootForceOffset == Vector3.zero)
rb.AddForce(turret.transform.right * shootForce);
else
rb.AddForce(turret.transform.right + new Vector3(0, shootForceOffset.y, 0) * shootForce);
yield return new WaitForSeconds(timeBetweenShots);
canShoot = true;
}
}
Answer by I_Am_Err00r · Jul 10, 2019 at 04:18 PM
The drag value in a rigidbody affects how fast it falls from gravity and might have been accidentally adjusted in the inspector (or a script could be mistakenly accessing it), the mass might not be very high if you have automass deselected, other than that in the project settings you can manually set the gravity to a different value, but those are the only ways I can think that a Rigidbody could affect fall speeds.
The drag and angular drag is set to 0, and the mass is set to 500
Then check the gravity settings under edit -> project setting -> gravity; by default I think it is 9.81 or something.
If that doesn't fix the issue, you mentioned that you added a rigidbody to this tank, did it have some sort of movement or physics parameters on it previously? $$anonymous$$aybe those are starting to linger.
Another thing you can do to test out is start a new project and import that tank and see if you are still seeing it when you import all the other components on there, if the tank falls normally in a new project, then something might have accidentally changed with your project settings or another script is affecting your tank movement.