Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
No need for attention on this anymore as someone down here made a good explanation of a better implementation: var eu = ccbGetSceneNodeFromName("Scenery/MinhaCasa/Eu"); // Player |
||||
|
Hola amigo. I believe, it will be more productive if you just describe the problem, and ask someone to implement the solution for you. My first reaction was: As far as I understand, it's just a script which closes or opens a door by pressing E if the player is close enough and is looking at the door. Also do you have a single door in your game? How you code is going to handle multiple ones? |
||||
|
Also a door in your script opens instantly. So your model has 90 degrees rotation, and then in the next frame its 180. |
||||
|
He wants door to open in 300MS I will send you the code but okeoke is right -this code cant be very useful - maybe useful to see how to convert preudocode into real code. |
||||
|
HERE: https://drive.google.com/file/d/... To make it better coder needs to know your goals with script.. so coder can use his own imagination to make things work as they should. Current script i made i tried to follow the instructions as much as i was able to. You didnt had BoundingBox request before when i readed this post.. anyways mine does same thing. This script is for free of cource. I have made door behavior also .. its free also and does all the door logic for you. https://5v3n.itch.io/coppercube-... |
||||
|
Probably, I don't understand the problem, but I mean, what is the point? If you want a door to open: 1. Create a folder with door nodes 2. Create class Door, which will have a door state, door position and reference to a door node as properties; 3. Before first draw collect all nodes from the doors folder, wrap them into Door class and put into the array; 4. On each frame check distance to each door, you already have their positions stored as an object property 5. If distance is less than some value, raycast and check if player is looking to the door - if yes, store door reference to a variable, if player is not currently looking at any door - nullify the variable. 6. If players presses E, check if the variable has some reference, and the player has a correct key. If so - change the door state; That way you don't need to code each door - just do it once. If you want door properties like, for example, key id, or if the door should open left or right, you can add these to the door's name. So you door node name looks like "door_0_left_key0". On the step of collecting all doors to the array you just split the string by _ and get all additional parameters you need. Also it's not a good idea to just change the rotation each frame, since while the object rotates player can clip into it and stuck inside the door or nearby wall. I believe, it's better to use animated door model and an invisible barrier, which is removed if the door opens. That way you also don't need to care about rotating the door each frame - it will be done by animation. And you also can have different animations like sliding doors, double doors and etc which all use the same code. In my opinion, this would be the more or less correct way to handle that - and the solution doesn't look anything like the provided code. I'm trying to say, if you want to learn to code, just try to code properly, if you want the job to be done - define your problem and let the guy who will be working on it decide how it should be done. |
||||
|
Thanks Svan and Okeoke, Indeed the reason I was going onto scripting is so a code could work for all the doors like Okeoke said, so I'll take a good read on your idea. Haha yeah the door does lock me into it sometimes, I thought about shifting models to avoid that. So the animated door is more performance than the rotating one it seems huh.. |
||||
|
lol...You can do this without code ... It is really simple |
||||
|
https://www.youtube.com/watch?v=_cRaikT9m4s |
||||
|
Don't forget to use the javascript function (update physics geometry) or you will not be able to pass through the newly opened door. Coppercube will think that the door is still in it's starting position |
||||
|
I'll just say that this is pretty easy to do with no coding in Coppercube on hover make set a variable to 1 on proximity do something if variable has value +1 to another variable behaviors triggered by events If E is pressed and variable has value 2 open door |
|