- Home /
Fixing instantiated object in one direction?
Hey guys! How are you?
I'm developing a 2D shooter, side view. My character only walk in X axis and have a variable to verify the direction of the character. Depending on the direction, the bullets are instantiated from objects positioned on the sides of the main character. The problem is: everytime I shot in a certain direction and change the side of the character, the bullets are going in one direction also change direction.
For example: if I shot to right, the bullets go to right, but if I change the direction of character to left before gameObject's destruction, the bullets also go to left.
The bullet's code:
var bulletSpeed : float = 10.0;
var distance : float = 5000;
var lifeTime : float = 0.5;
private var charging : boolean = false;
private var spawnTime : float = 0.0;
private var tr : Transform;
function Start()
{
tr = transform;
spawnTime = Time.time;
}
function Update()
{
if(GameObject.Find("mainCharacter").GetComponent(scriptPlayerControl).moveDirection == 1)
{
tr.position += - tr.right * bulletSpeed * Time.deltaTime;
distance -= bulletSpeed * Time.deltaTime;
if(Time.time > spawnTime + lifeTime || distance < 0)
{
Destroy(gameObject);
}
}
if(GameObject.Find("mainCharacter").GetComponent(scriptPlayerControl).moveDirection == 0)
{
tr.position += tr.right * bulletSpeed * Time.deltaTime;
distance -= bulletSpeed * Time.deltaTime;
if(Time.time > spawnTime + lifeTime || distance < 0)
{
Destroy(gameObject);
}
}
}
I want to fix the direction of the bullet in its firts direction till the destruction
Some help? Thanks!
Your answer
Follow this Question
Related Questions
How to make random alien fire and not all of them at once.. 2 Answers
Bullets Based on Orientation 1 Answer
Set parent of instantiated object. 0 Answers
Deploy object avoiding collisions 0 Answers
How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers