- Home /
Stop player being launched on switch weapons
I don't think this has been asked before, I couldn't find it anywhere, but if it has, sorry.
I have made a script to swap weapons when the player is near a weapon on the floor and they press E. It works perfectly, but there is a problem with the part of the script that drops the original weapon. It works by disabling that weapon's scripts, enabling it's collider and unfreezing it's rigidbody. This works, but has the unwanted side effect of launching the player several hundred metres into the air. I think this is because when the weapons rigidbody and collider are enabled they are within the player, and push it. Of course, if they are not enabled, the weapon will just hover in the air, which is not what I want. Is there a way to avoid the player being launched whilst still dropping the old weapon on the floor?
If it makes a difference there is a capsule collider with a rigidbody attatched to the player so that they will be able to push rigidbodies
You could perhaps just make it "spawn" a few metres in front of the player?
Do you have a script that makes you move the player higher when a collider is "inside" him? I seem to recall a similar question a month or two back but forgot the cause ><
Thank you for your answer.
No, the player is just the default FPS controller with a capsule collider rigidbody parented to it. I have tried your idea and it works perfectly, but if their is a wall in front of the player it will disappear through it, and the weapon will be lost. Is their any way to make sure it stays this side of any colliders? maybe a rigidbody sweep test?
follow this tutorial to make the gun visible : http://www.youtube.com/watch?v=bBrr-esgV8E
The problem is that the gun, when dropped, physically is going through walls/floor and falling into space. Sorry. i should have made that clear. Thanks for the link though, I have been looking for how to do that for ages!
Answer by dorpeleg · May 30, 2013 at 04:04 PM
You can use Physics.IgnoreCollision to make sure the weapon is not colliding with the player.
Your answer
Follow this Question
Related Questions
Colliding Melee Weapons 2 Answers
Trouble with OnCollisionEnter and Exit 1 Answer
Rigidbody: how to get collisions for the current frame ? 0 Answers
Car dynamics? 0 Answers
Avoid Player bouncing when colliding with objects 3D 1 Answer