- Home /
Question by
dhruvmohandatta1234 · Oct 14, 2017 at 02:39 AM ·
rotationprefabvector3projectilepivot
The bullet only moves in one direction and does not rotate with object. Code:
Player projectile code:using UnityEngine; using System.Collections;
public class playerprojectile : MonoBehaviour { public GameObject spawnPosObj; public GameObject bullet; // Use this for initialization void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey (KeyCode.Space)) {
Instantiate (bullet, spawnPosObj.transform.position, Quaternion.identity);
}
}
}
code for bullet: using UnityEngine; using System.Collections;
public class bulletscript : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.back*60* Time.deltaTime);
}
}
Comment
Answer by FlyingHighUp · Oct 14, 2017 at 03:10 AM
Instead of
transform.Translate (Vector3.back*60* Time.deltaTime);
Use
transform.Translate (-transform.forward*60* Time.deltaTime);
Your answer
Follow this Question
Related Questions
Physics related rotation problem. (a weird one) 0 Answers
Freeze object rotation on Polybrush 1 Answer
How would I rotate an object relative to another without parenting? 2 Answers
Calculate Vector3 for rotation or just change pivot; 0 Answers
Projectile not launching from correct place - rotation or positioning issue? 0 Answers