- Home /
My projectile wont fire in the right direction
I cant seem to find out what is causing my projectile to fire in the wrong direction, if i put forward it goes up and to the right, if i put right it goes left. any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class cannonZone : MonoBehaviour {
public GameObject cannonballPrefab;
public Transform SpawnPoint;
private bool inZone = false;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (inZone)
{
if (Input.GetKeyDown ("e"))
{
FireCannonball();
}
}
}
void FireCannonball()
{
GameObject cannonball = (GameObject)Instantiate (cannonballPrefab, SpawnPoint.position, SpawnPoint.rotation);
cannonball.GetComponent<Rigidbody> ().AddForce (transform.forward * 80, ForceMode.Impulse);
}
void OnTriggerEnter(Collider col)
{
if (col.gameObject.tag == "Player")
{
inZone = true;
}
}
void OnTriggerExit(Collider col)
{
if (col.gameObject.tag == "Player")
{
inZone = false;
}
}
}
Answer by Volturna · Mar 11, 2017 at 07:54 AM
Are you sure whe you instatiate that cannon ball it is facing the direction you want you projectile to go? Try changing you prefab angles to see what happens
Answer by tinglers · Mar 10, 2017 at 03:40 PM
make sure the prefab does not have a rotation to it as it will add onto the transform of the spawnpoint.,does the cannonball prefab have a rotation to it? it will add onto the rotation of the spawnpoint.
Your answer
Follow this Question
Related Questions
How can i fix this shooting code in a 2D plane? 0 Answers
Firing projectiles on the XZ Plane 2 Answers
I shoot a projectile, but its rotation is wrong (c#) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers