my bullets are flaoting upwards and i dont know why?
my bullets are shooting floating upwards and I don't know why they float hi to the ceiling instead of shooting forward please help
2 scripts on them below
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletFireScript : MonoBehaviour {
public float fireTime = .05f;
public GameObject bullet;
public int pooledAmount = 20;
List< GameObject> bullets;
void Start () {
Debug.logger.logEnabled = false;
bullets = new List <GameObject> ();
for (int i = 0; i < pooledAmount; i++) {
GameObject obj = (GameObject)Instantiate (bullet);
obj.SetActive (false);
bullets.Add (obj);
}
InvokeRepeating ("Fire", fireTime, fireTime);
}
void Fire()
{
for (int i = 0; i < bullets.Count; i++)
{
if (!bullets [i].activeInHierarchy)
{
bullets [i].transform.position = transform.position;
bullets [i].transform.rotation = transform.rotation;
bullets [i].SetActive (true);
break;
}
}
}
}
--------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BulletScript : MonoBehaviour {
public float speed = 5;
// Update is called once per frame
void Update ()
{
transform.Translate (0, speed * Time.deltaTime, 0);
}
}
Answer by Chubzdoomer · Jan 29, 2017 at 09:00 PM
Shouldn't you be manipulating the x-coordinate in transform.Translate (instead of y) since you're wanting the bullets to fly horizontally?
Try this:
void Update ()
{
transform.Translate (speed * Time.deltaTime, 0, 0);
}
If they're moving backwards, you can try either setting speed to -5 ins$$anonymous$$d of 5, or you can just type -speed, which will get you the negative version of speed, like this:
void Update ()
{
transform.Translate (-speed * Time.deltaTime, 0, 0);
}
Your answer
Follow this Question
Related Questions
transform.Translate is too smooth 3 Answers
Object reference not set to an instance of an object + array of positions 1 Answer
Move a player in the direction he is facing. 1 Answer
How to prevent z position change in AR? 0 Answers
Translate more than one object on update with the same function 0 Answers