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

How to make a ball stay in the air longer when force is added?

$
0
0
I am making a game and the player is allowed to pick up and throw a ball in the direction of where the camera is facing. I have 2 scripts for this that are exactly the same except one is for the x and z axis and the other is for the y axis. I'm trying to make it so that when the player throws the ball it goes straight and not curve up and then back down. Here is my script using UnityEngine; using System.Collections; public class throwx : MonoBehaviour { public Rigidbody rb; public Transform t_Camera; // Drag&Drop your camera over here from the inspector. private Vector3 v3_Force; // Force reference vector. public float f_Multiplier; // A multiplier value if the force wouldn't be enough. public GameObject carryact; public Transform ball; // Use this for initialization void Start () { } // Update is called once per frame void Update () { if (Time.deltaTime == 0f) return; if(carryact.activeInHierarchy) { if (Input.GetMouseButtonDown(0)) { v3_Force = t_Camera.forward; ball.GetComponent().AddForce(v3_Force * f_Multiplier, ForceMode.Force); } } } }

Viewing all articles
Browse latest Browse all 1264

Trending Articles



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