- Home /
Object won't collide with Player unless Player is moving
So yeah. Basically I have a simple Galaga/Space Invaders type game, and I have a power up that drops randomly from ships and flies towards the player at the same speed as the enemy ships. If the player moves to get it, the player usually will obtain the power up. However if the player ISN'T moving whatsoever, the powerup will pass right through. Both the player and the object are using simple box colliders, and are simply boxes with textures painted on.
I'm a beginner in both Unity and Javascript, any tips/help would be appreciated.
Post your code so we can see what the issue with the code. Other wise we got no clue how you're coding it to work therefore we don't know where to start.
I'm pretty sure the character has to be moving to collide/trigger and object. I have often times wondered about this but it hasn't been a problem for me. I'm sure someone will give you an answer.
Down to business. Your power ups have rigidbodies right? if not you definitely want to add some (add some to your character too if it doesn't have one.) you need rigidbodies to activate collisions.
again i don't know what causes this problem to happen but, i have observed it.
another useful thing to know would be : are you using transforms to move your power up / character or force.
hope this helps i hope you get your answer (for i too am curious about this)
rednax20 comment just made me remember, ins$$anonymous$$d of using collide, use rayCast and see if it hit the player and if it does give the power up set the rayCast distance to 0.1 o the player has to be right on it or infront of it. This should solve your issue, make sure to put this script on the powerup and to put it in the update to see if it hit anything on each frame.
Answer by asylum101 · Oct 23, 2013 at 12:24 AM
I feel like an idiot, I forgot to put rigid bodies on my power up. /facepalm. I put them in and it looks like its working just fine.
It's weird though, like I said, the power ups WERE working, not exactly as I had intended though. I could pick up the powerup so long as I was moving, once I sit still.. nothing.
I'm using transforms to move my stuff, is force better? What are the advantages of one or the other?
Raycast- man I still need to learn how to do that. I was trying to make a simple platformer engine a while back and I could not for the life of me figure it out.
Thanks for the tips guys!
force creates a movement that can be increased exponentially, and be slowed by other forces like gravity angular drag (friction) while keeping there added momentum. transforms are simpler and are often enough (if not better) for a quick not necessarily realistic game. (by realistic i mean like a game where a ball has to fall in precis places, not like galaga no matter what the graphic quality);
each has its own ups and downs i was just wondering incase it made a difference, again i didn't know what caused the problem. although it looks my rigidbody idea help you solve it.
Quishtay all the way
Your answer
Follow this Question
Related Questions
Collision, change skybox in game 1 Answer
Parent Object 0 Answers
Enable objects to enter the trigger 2 Answers
Have script detect which collider 2 Answers
Object Carry 0 Answers