Hey guys glad that you are here and thanks for any help! ![]()
Either way lets get to my question I am working on a fps project and I have come to a point where as the player shoots I want to spawn a bullet casing I did this a while ago on a prototype project where it worked perfectly but since I deleted the project and can’t remember the way I did it I tried remaking it out of nothing and there is issues which is why I am here at first here is the code for the bullet casing and the weapon spawning the bullet casing. Then the question will be below them.
This is the script attached to my bullet casing prefab.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(Rigidbody))]
public class CasingHandler : MonoBehaviour
{
[Header("Variables")]
public float Velocity = 5;
public float MinumumRotation = 5f;
public float MaximumRotation = 15f;
private Rigidbody rb;
void Start()
{
gameObject.transform.parent = null;
rb = gameObject.GetComponent<Rigidbody>();
}
private void FixedUpdate()
{
rb.velocity = transform.TransformDirection(Vector3.right * Velocity);
}
private void OnCollisionEnter(Collision collision)
{
Destroy(gameObject);
}
}
Here is my script where I instantiate the bullet at a empty gameobject.
void InstantiateBulletCasing()
{
Instantiate(BulletCasing, CasingPoint.position, Quaternion.identity);
}
So the issue is once the bullet casing is spawned it just starts floating to where it’s right transform point is what I wanted to do is add an impulse at the start to the right of the bullet to eject it but it doesn’t matter where my player looks the casing will float to the original right axis. I will upload a video below to demonstrate the issue and for the life for me I can’t figure it out if any one has a idea please explain it to me I want to learn and make sure I fix this thank you so much for your time I hope you can help!
The video :