Quantcast
Channel: Questions in topic: "addforce"
Viewing all articles
Browse latest Browse all 1264

Rigidbody falling very slow

$
0
0
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(); rb = GetComponent(); } 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().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; } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>