I’m back at it again with another problem.
This time, it’s about bullets and raycasting. My bullets are only firing in one direction and I have no idea as to how to make it relative to the player’s rotation. This seems like a pretty easy thing to fix, but I just can’t come up with an idea as to how to fix it.
Here’s the code, props to anyone who can lend me a hand.
`using UnityEngine;
using System.Collections;
public class BulletMovement : MonoBehaviour
{
public int speed = 20;
float timer = 20f;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector3.back * 20 * Time.deltaTime);
if (Camera.main.WorldToViewportPoint(this.transform.position).y > 1)
{
Destroy(this.gameObject);
}
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Enemy"))
{
Destroy(other.gameObject);
Destroy(this.gameObject);
}
}
}
`