I am making a first person game that takes place mainly in hallways and buildings, and as such, I need to have doors. I want to make the doors like the the ones in Amnesia: The Dark Descent, by which I mean that if you click and hold down the left mouse button on a door, then the door opens away from you slowly as you slide the mouse forwards, and the opposite happens if you slide the mouse backwards. I am not very experienced (and just plain bad) at scripting, so is there a script that I could use? Any suggestions would be appreciated greatly.
3 Answers
3There isn't a certain script you can use I'm afraid. The only thing I can suggest is that you try breaking what you want to do down into smaller and smaller steps, and work out how to acheive each one in turn. For example, you may decide to break it down as follows:
- Import the model of the door (and wall?) from your choice of 3d modelling package into Unity
- Detect when the player presses the left mouse button down
- Work out whether the mouse pointer is over the door handle when it is pressed
- Track the change in vertical position of the pointer while the button is down
- Move/animate the door based on how far the mouse has moved
These are all extremely simple steps though, coding wise. All but step one can be done in a single line of code each.
– anon73820239very nice answer, i suggest the detection with trigger and the trigger box, then the mouse recognition this way, the player object needs to be on range of the door, then make the interaction with the mouse, thumbed you up
– ponchoUse Configurable Joint. It was made for doors.
As far as i can tell, the player prefs will stay on your specific machine regardless if you play the game through the editor or the build. The simple way to fix this is to run a bit of code that deletes the player prefs, run that code once and then delete that code or comment it out, and THEN build your game.
– boatakksWith DragRigidBody script ^^
Don't say you're bad at scripting. It's negative thinking and only serves to make you think you can't do things that you can, with practice.
– Jessy