- Home /
Instantiating projectile object is affecting the movement of instantiater
Hello. I'm trying to create a game where your character's movement is based on where you are shooting. So if you shoot down, it'll essentially be like jumping. I have two guns, so you can be shooting downwards with both to speed up your ascent.
I'm having a bit of trouble with the creation of the projectile. When I add the impulse to the character without creating a "Shot" prefab, my character moves as expected (smoothly moving upwards when both guns are shooting downwards or slightly to the side). However when I create the projectile, sometimes it seems the character gets stuck or something on the prefab, causing the movement to be jerky and unsmooth.
I've tried playing around with my "Shot" prefab, removing its rigidbody and collider and such. It seems that when the collider is not active, this problem doesn't exist and the character can move smoothly. However I am going to need that collider to perform other checks.
Another thing I am doing is calling Physics.IgnoreCollision. This seemed to work in terms of my projectile not getting destroyed when it hits the character, but the jerkyness still exists. Here's my code for that call:
GameObject shot = Instantiate(projectile, hand.position, hand.rotation) as GameObject;
Collider colliderBody = transform.parent.GetComponentInChildren<BoxCollider>() as Collider;
Physics.IgnoreCollision(colliderBody, shot.collider);
shot.SendMessage("SetVelocity", -firePower * firePower * lastRotation);
I am thinking maybe there's another rigidbody it's getting stuck on within my character, but I don't have any colliders or rigidbodies attached to it besides the one that it'd find with GetComponentInChildren BoxCollider(). Any suggetsions on what I can do to fix this jerkiness?
u need to learn about LAYERS in unity physics, it's a basic of video games.
here's the full explan
http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
enjoy!
@Fattie: Thanks for the link! So I added a projectile layer to my Shot prefab, and a Player layer for my player (I added it to the parent Player object, it asked if I wanted to apply to all children, I said yes please). In that layer matrix under physics I have it so projectiles and players won't collide with one another. Yet I am still getting this jerky motion! I do not understand what's going on, this bug has been bugging for 3 weeks now :@
I've also tried instantiating the object far away, setting ignorecollisions and then moving the object back. Still collides with my player, messing up his motion (sometimes the player will lose all momentum, and it looks really jerky).
http://answers.unity3d.com/questions/13659/how-to-ensure-projectiles-dont-bump-into-each-othe.html
I also tried that link, ignoring collisions in the start of the projectile. Still jerky! I have no idea what this problem could be
Answer by jeffreyf · Oct 22, 2012 at 09:53 PM
I found the problem. After spending hours looking into this, testing various physics etc, I realized that one of my scripts was doing a downwards raycast that would zero the velocity when it hits something. So stupid and frustrating!
Your answer
Follow this Question
Related Questions
How to calculate projectile (baseball) distance with drag factor 1 Answer
Controll 3D Rigidbody Projectile with Joystick 1 Answer
Very intermittent Collsion with grenade projectile and room with mesh collider. 1 Answer
Dart projectile collide with another dart in the board 0 Answers
Rigidbody Controller Jittery 1 Answer