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);
}
}
}
}
↧