This question was
closed Feb 25, 2016 at 03:55 PM by
Son_ofSpartacus for the following reason:
The question is answered, apparently it was just a matter of time till I figured it out myself.
Question by
Son_ofSpartacus · Feb 25, 2016 at 10:24 AM ·
2dinstantiatescripting beginnertop down shooter
Projectile Instantiating at opposite position
In Unity2d, I'm making a top down shooter with tanks. My player controlled turret rotates and the bullet shoots in accordance to the turret's angle... In the opposite direction. The bullet seems to spawn at the turret object's default 'up' position. The thing is I have no idea how to flip it. How can I flip the Instantiate position of the bullet in the script or adjust the sprite so that the bullet isn't firing out the butt end of the tank turret? Here's the script. If anything looks hilariously misspelled, that's probably because my xkcd substitutions chrome plugin has leaked into this.
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class PlayerShoot : MonoBehaviour
{
public GameObject bulletPrefab;
public float fireRate = 0.5f;
private float nextFire = 0.0f;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("space") && Time.time > nextFire)
{
ShootBullet();
}
}
void ShootBullet()
{
nextFire = Time.time + fireRate;
GameObject Clone;
Clone = (Instantiate(bulletPrefab, transform.position, transform.rotation)) as GameObject;
}
}
Comment