- Home /
This question was
closed Dec 21, 2014 at 02:59 AM by
meat5000 for the following reason:
The question is answered, right answer was accepted
Projectiles won't fire correctly. Help! (C#)
Projectiles will only fire correctly between 42 and 50 degrees, any other angle that i have tried sends them either directly down or backwards. Please take a look at the code:
using UnityEngine; using System.Collections;
public class Cannon : MonoBehaviour { public GameObject projectilePrefab; public int Angle = 10; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
}
void FixedUpdate()
{
if (Input.GetButtonDown("Fire1"))
{
GameObject projectile = Instantiate(projectilePrefab, transform.position, transform.rotation) as GameObject;
projectile.rigidbody.AddRelativeForce(new Vector3(0, 0, -1000));
}
}
void LateUpdate()
{
transform.rotation = Quaternion.Euler(Angle, 0, 0);
}
}
helpimage.png
(198.0 kB)
Comment
@meat5000 yes do I need to tag the question as answered or something?
Indeed, click the tick under the thumbs next to the answer. You may even close it if it requires no further input. Close link is under your question.