- Home /
C#: "Pushable" obstacles for a puzzle
Hi!
I'm kinda noob on coding and I need to make a game for university.
In this game, you can push some objects in order to solve some puzzles (Pokémon style: http://youtu.be/Rb9GQ1Q-maY?t=6m55s).
We decided to make it similar to Animal Crossing (http://youtu.be/EsEF8Aa0CXE?t=22m31s): you press the "interact" button and the character enters in the "push mode", but, unlike Animal Crossing, you can't pull and it doesn't need to be tile based.
I already searched for this, like I said, I'm a "newborn programmer", I don't know if I'm seraching correctly, I don't know advanced coding and stuff, just do what I can to make it work. The main problema actually is that I must finish this project as soon as I can and I'm stuck on this "pushing things" issue.
I kinda made it work (unfortunatelly, using rigidbodies), but I'm having some troubles. What I already did:
If next to the pushable object, you can interact with it
Pressing the interact button makes the player drag to a "central position", to align it to the object (like a lot of games do)
If you are in the "push mode", your animation changes, you can't walk to other directions than forward, pushing the desirable object
If you release the interact button, you exit the "push mode"
If the pushable object touches anything that has a collider, you can't push it to the direction that you were pushing it anymore, even in the "push mode" (that's seems kinda obvious, but it's not "natural" to Unity, cuz the pushable object would normally also push a lighter object)
Like... It's done. But with bugs. Annoying ones.
It works fine until it collides with another object, you exit the "push mode" and try to push it again pressing the interact button and the button that makes the character walk at the SAME time. I don't know why it happens and don't know when (cuz, with some objects, it doesn't happen), but, when all this happen and I start pressing the buttons at the same time, the object goes through the other, usually doors and other pushable objects (and also appears an error in the console).
Another very specific bug is that, when I try to force pushing the object against some other specific objects, the room where the player is starts to flick. I am almost sure that this happen cuz the entire room has a trigger that, while onCollisionStay with the player, makes the room and all its children change their layer, so the camera stop rendering them. So it seems to be this, just don't know why on earth pushing an object and making it touch another "simulate" the player exiting the room trigger but making it coming back (cuz it is a onCollisionStay, I changed to onCollisionEnter and, instead of flickering, the room just disapear when I force 2 objects to touch each other).
I don't like rigidbodies, but this is all that I got at the moment. I'm just using it on these pushable objects, there are no other objects with rigidbodies in the scene.
And, please, SORRY ABOUT MY ENGLISH.
Any one has any suggestion? Any tutorial? Need more information?
If you want to know, tom make all this work, I created 4 gameobjects with rigidbodies, deleted their mesh rendering, leaving just the collider. The 4 colliders are children of the pushable object and I use the logic of "when the player touches one of the sides (one of the objects), the player can only push the object to a specific direction (forward), if the opposite side touches anything that is not the floor, the player or any of the components attached to the pushable object and the object itself, then you can't push it anymore, you need to interact with another side of the pushable object (one of the 4 colliders) etc".
Sorry about the "bible" and thanks for everything
And I also will keep on seraching, maybe I find the "answer" to my problem before anyone.
That's an awful long problem description and based on the length I can only guess it's multiple issues; narrowing things down to one problem might get you better results.
Why not just make it so when the character enters a Trigger zone around the object control of the character is duplicated into the object itself. To do so, simply make a basic movement script for the object and then add an OnTrigger event to toggle the script on and off. Considering you said you already have a specific mode for moving objects, you should be able to tell a Trigger event if the $$anonymous$$ove $$anonymous$$ode is active, then activate the objects move script. Then if you are in movement mode and you collide with the trigger your character and the object will move in-sync with each other.
Your answer
Follow this Question
Related Questions
How to make certain rigidbody2d's not able to push other rigidbody2d's? 2 Answers
How to prevent a rigidbody from pushing other rigidbodies? 1 Answer
Detecting when Player stoped to push a rigidbody? 3 Answers
Making Colliders/Triggers or Rigidbodies move a Character Controller 5 Answers
Rigid bodies not to push each other? 4 Answers