RigidBody only moves when I remove Collider
I'm trying to create Flappy Bird as a tool to learn Unity & essentially I've added this script to the "pipes". When I remove the Collider they work perfectly fine, but obviously I need the collider for them to function properly. When I add the collider they just sit there & bump into each other.
Any ideas?
#pragma strict
public var speed : int;
function Start () {
var newSpeed : Vector2;
newSpeed.x = speed;
newSpeed.y = 0;
GetComponent.<Rigidbody2D>().AddForce(newSpeed);
}
Answer by Magius96 · Mar 18, 2016 at 04:11 AM
Ok, so you need the colliders to see when the player hits them, but you don't want them to hit each other. This is actually simple. Click the checkbox on your pipe colliders to make them triggers. Then in the player, look for trigger events.
Now, this will have the unfortunate side effect of the player not actually colliding with the pipes, but if this is to be like the original flappy bird, that is fine since as soon as the collision occurs the player is dead anyways.
Ok. I understand what you're going for; however, my idea for the game I was going for was going to be to have the collision knock the player off the screen, which would result in the game over.
When you detect the trigger, change the velocity of the player appropriately. So if the player was moving right (1, 0, 1) and you want them to fall down off the screen, then you might set the velocity to (0, -1, 0).
Oh, and your probaby better off using
void OnTriggerEnter2D(Collider2D other)
Assu$$anonymous$$g your game is 2D, otherwise you'll want
void OnTriggerEnter(Collider other)
Answer by SynGT · Mar 22, 2016 at 03:45 AM
I just went a different way with this. Your OnTrigger helped, but it didn't quite answer the question.
Your answer
Follow this Question
Related Questions
RigidBody2D velocity randomly drops to zero 1 Answer
Enemy AI Script Error 1 Answer
AddForce rigidbody 2d not moving object 2 Answers
how to fire my player out of a Cannon? 0 Answers
Rigidbody2D AddForce Impulse not working on X axis 5 Answers