Hi.
I have an issue with my Wepon script. I want to shoot in direction where my player is turned. But with mi script, I shoot only on world X axis. Bullet flies left or right, depends on the rotation on Y axis. But of course, I want to shoot forward. This is my script. Any ideas?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Weapon : MonoBehaviour
{
[SerializeField]
private Transform firePoint;
[SerializeField]
private Rigidbody bulletPrefab;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Mouse0))
{
Shot();
}
}
private void Shot()
{
Rigidbody bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
bullet.AddForce(firePoint.transform.forward * 10, ForceMode.Impulse);
}
}