How to translate an object in an unknown angle ?
I'm creating a sort of tps and I want to shoot a bullet in the rotation position of the player but it dosn't work. Here the part that create the bullet and shot it (supposed to shot it). I don't really understand why it's not working.
void shot()
{
float angleX = transform.rotation.eulerAngles.x;
float angleZ = transform.rotation.eulerAngles.z;
float posPlayerX = transform.position.x;
float posPlayerZ = transform.position.z;
Instantiate(bullet, new Vector3(posPlayerX+2, 0.44f, posPlayerZ), Quaternion.identity);
bullet.transform.Translate(Mathf.Cos(angleX) * bulletSpeed * Time.deltaTime, 0f, Mathf.Sin(angleZ) * bulletSpeed * Time.deltaTime);
}
Thanks for helping
Answer by xxmariofer · Apr 22, 2019 at 11:01 AM
because you need to call translate method in the uppdate so it gets called every frame not only once when is created
also after seeing your comment, i have checked you are not moving the instantiated bullet but the bullet used as a prefab, you need to save that bullet in a variable and move it in the update since it has to move all the time
Your answer
Follow this Question
Related Questions
how do I rotate an object without affecting later rotation? 0 Answers
when trying to rotate, the object transforming itself 0 Answers
How can i clamp rotation between a negative value and a positive value 0 Answers
transform.rotation interferes with transform.Rotate 1 Answer
How would you rotate smoothly? 0 Answers