- Home /
Projectiles always going to the left and not forward
Hi,
I have a cube that is supposed to fire prefab cylinders which have a rigidbody. However, the cylinders are always coming out of the left side of the cube, instead of the front. I've tried changing the direction and using AddRelativeForce() but it will always come out of the left side.
Could someone explain to me why that is? Thanks.
void FixedUpdate () {
speed = Input.GetAxisRaw("Horizontal") * acceleration;
amountToMove = new Vector2(speed, 0);
transform.Translate(amountToMove * Time.deltaTime);
if(Input.GetButtonDown("Fire1")){
Debug.Log("Fire1 pressed!");
laser = Instantiate(laser, transform.position, transform.rotation) as GameObject;
laser.rigidbody.AddForce(laser.transform.forward * Time.deltaTime);
}
}
Answer by citizen421 · Oct 29, 2013 at 03:50 PM
That didn't work either. Thank you though. I just solved the issue by taking a look at this example:
http://unity3d.com/learn/tutorials/modules/beginner/physics/assignments/brick-shooter
Answer by MasterTim · Oct 29, 2013 at 06:38 AM
void FixedUpdate () {
speed = Input.GetAxisRaw("Horizontal") * acceleration;
amountToMove = new Vector2(speed, 0);
transform.Translate(amountToMove * Time.deltaTime);
if(Input.GetButtonDown("Fire1")){
Debug.Log("Fire1 pressed!");
laser = Instantiate(laser, transform.position, transform.rotation) as GameObject;
laser.rigidbody.AddForce(Vector3.forward * Time.deltaTime);
}
}
you have to take Vector3.forward
Your answer
Follow this Question
Related Questions
2D Shooter - shooting forward at the current rotation 2 Answers
Adjust object forward to force direction 1 Answer
AddForce makes cube 2 Answers
Bow and Arrow functionality in Unity3d 0 Answers