- Home /
Bullet follows new position
So I am making a game in unity2D js, and it is a top down space shooter, I have the character rotation down, and its movement, but I'm having trouble making it shoot. I want it so the player spawns a bullet, and the bullet goes to where the user clicked, and keeps going. However, what is happening is the player shoots somewhere, the bullet does excatly what its designed to, but then when you shoot another bullet, the first bullet goes where the second one is.
My Code: #pragma strict
var mousePos : PlayerControls.mouse_pos;
var bulletSpeed = 15;
function Update(){
transform.position = Vector3(transform.position, mousePos.position, bulletSpeed * Time.detlaTime);
}
Please help, thanks!
Answer by SolutionStudios · Jul 17, 2015 at 10:38 AM
Try this:
#pragma strict
var mousePos : PlayerControls.mouse_pos;
var bulletSpeed = 15;
private var thisBulletsTarget : float;
function Start () {
thisBulletsTarget = mousePos.position;
}
function Update(){
transform.position = Vector3(transform.position.x, thisBulletsTarget, bulletSpeed * Time.deltaTime);
}
You have forgotten the "new" keyword before Vector3
in the Update
You don't need 'new' in Js. Thats C#.
But, I did miss the '.x' after transform.position and spelt Time.deltaTime wrong, which I just corrected.
Oops, you are right, I make my scripts in C# only and I mistook...
Your answer
Follow this Question
Related Questions
EMERGENCY!!! PLEASE HELP!!!!! 3 Answers
Space Invaders movement? 1 Answer
Starting a solar system project 1 Answer
LookAt not working, points in wrong direction. 1 Answer
Instantiating a prefab/bullet and sending it to my mouse position?? 0 Answers