Quantcast
Channel: Questions in topic: "ignorecollision"
Viewing all articles
Browse latest Browse all 148

projectile must ignore collision with itself

$
0
0
i have this scirpt var projectile : Rigidbody; var speed = 100; var barrel : Transform; var shots : int = 0 ; var maxShots : int = 1 ; function Update () { fwd = transform.TransformDirection(Vector3.forward); if ( Input.GetButtonDown ("Fire1") && shots < maxShots){ Shoot(); } else if (shots >= maxShots) { Reload(); } } function Shoot(){ var bullet1 : Rigidbody; Physics.IgnoreLayerCollision(8,8, true); bullet1 = Instantiate(projectile, barrel.position, barrel.rotation) as Rigidbody; bullet1.GetComponent(Rigidbody).useGravity = true; bullet1.GetComponent(Rigidbody).AddForce(barrel.forward * speed, ForceMode.Impulse); shots ++; } function Reload() { yield WaitForSeconds(0.5); shots = 0; } which will instantiate a projectile and fire it while ignoring it' s own collsion this is because my projectile will spawn inside itself in the game if someone is going to say that i could just move the spawn out of the projectile my answer is i can't do that because of a animation i have for throwing the object (this animation is not in the script just yet ill implement it later) so i used a ignorelayercollision to prevent it from colliding with himself but whe i use it, it gives this error and wont spawn the clones NullReferenceException: Object reference not set to an instance of an object StoneFire.Shoot () (at Assets/MY Assets/Scripts/StoneFire.js:21) StoneFire.Update () (at Assets/MY Assets/Scripts/StoneFire.js:11) i have this same error on line 18 too but that one does not mess up my in game actions so i wont fix that now (if someone knows how to fix it you can say that too) can someone please tell me why my projectile won't spawn and give that error projectile information: it is a rigidbody is kanematic is off use gravity is off in editor but script enables it uses sphere collider and not a mesh collider because then i had to put is kanematic on and that would lead to a not moving bullet.

Viewing all articles
Browse latest Browse all 148

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>