So, i’ve been making my first game on unity and i have a problem. I did a lot of work making weapon and one of the things i made was spawning shells whenever player shoots. Shell uses Rigidbody for physics and everything went well untill i decided to add rigidbody component to the character controller object, and thats where the magic starts.
When the spawn of an object is triggered shell spawns on top of an collision of the player instead of spawning inside of it, and also the raycast detects player collision despite the fact that all of the features worked before adding rigidbody component
Code for spawning shell:
void Shoot(){
Pistol_walk_animator.SetTrigger("Shoot");
GameObject shell = (GameObject)Instantiate(shellobject,
shellspawner.position, shellspawner.rotation);
pistol_particle.Play();
RaycastHit hit;
if (Physics.Raycast(Cam.transform.position, Cam.transform.forward,
out hit, range))
{
ammunition_crate target = hit.transform.GetComponent<ammunition_crate>();
if(target != null)
{
target.damage(damage);
}
}
}