Where the bullet spawns when I shootballe Unité fraient
Salut, pour certaines raisons ma balle ne se reproduit pas où je dis à. Le point de réapparition est à la fin de mon tonneau, je prends sa position de transformation et sa rotation quand j'instancie la balle, mais elle se reproduit plus haut que le pistolet (bien plus haut). Voici le code que j'ai:
Animation anim; // Gun animation when shooting
AudioSource gunSound; // Gun sound when firing
public Rigidbody bullet; // I get the rigidbody of the bullet that will be spawned
public Transform spawnPoint; // The position of where it is supposed to spawn
void Start()
{
anim = GetComponent<Animation>();
gunSound = GetComponent<AudioSource>();
}
void Update()
{
if (Input.GetButtonDown("Fire1")) // If the left mouse button is clicked
{
Rigidbody bulletInstance;
bulletInstance = Instantiate(bullet, spawnPoint.position, spawnPoint.rotation) as Rigidbody; // This is where I don't understand why?!?!
bulletInstance.AddForce(spawnPoint.forward * 1000f);
gunSound.Play();
//anim.Play("GunShot4");
}
}
Aide :)
Donc la balle n'apparaît pas à la position de la transformée donnée? Y a-t-il des scripts attachés qui pourraient être téléportés? – HalpPlz
Outre le script de contrôleur de caractères qui est sur le parent du parent et qui n'affecte rien avec le pistolet, non, il n'y a rien. Et oui, au lieu d'apparaître à la transformation spawnpoint (gameobject vide), il apparaît plus haut comme dans l'image liée en haut de la description (première ligne) – Manu
Ah, il se peut que "public Rigidbody bullet" soit "public" GameObject bullet "et vous devez l'instancier" GameObject "au lieu de" Rigidbody ". Vous pouvez référencer le corps rigide avec gameObject.GetComponent (); – HalpPlz