Ladders are evil, ugh...
Ladders, Some people like them, some people don't. I like them, but I don't like making them. I just spent 9 straight hours after work to get the semblance of a half working ladder. The challenges were mind boggling for my sleep addled brain.
I initially started a few days ago. I wanted ladders for the game I had planned. Specifically with functionality similar to Counterstrike: Source and Left 4 Dead. So being the lazy good dev I am, I went to Youtube to see how people using Unity were accomplishing it. The first immediate thing I noticed was that they all used triggers/colliders to accomplish this goal. They used 3 features of their trigger/collider: OnEnter, OnStay, and OnExit.
I was shown a script where all of the actions were implemented, but I realized from the time I spent making sourcemod scripts that I would need to control every entity that touched my trigger, especially if I ever did multi-player. So I wrote a heavily modified collision trigger. OnEnter was not that hard, all that was is the very first instance that an entity collided with the trigger I call a function once, and add it to a list so it would not be called again. OnStay is just a duplicate of the Collision function in Leadwerks. OnExit was the spawn of satan. On exit tells you when an entity leaves the trigger. Well in Leadwerks when something leaves a trigger it's gone. You can have a list of entites that you populated but since the collision trigger can't tell you whats missing the list becomes useless. So I ended up creating a a list paging system in order to track what entity has left.
So I created 2 lists: old and new
and a timer : Timetillupdate
When an entity collides for the first time I set it's state to onenter.
When it collides a second time i change it's state to onstay
when timetillupdate runs out i check the old list against the new. If there is something missing in the new list, i set that entity to onexit. Then i page the new list into the old list, then empty the old
Seems simple enough, but it's my first time doing this, and Leadwerks is my first game engine where I have coded anything of note, so I probably went the long way round, and messed something up, nevertheless it functioned properly.
Now the ladder. After watching about 3 videos on YouTube,
When I get more time/experience I will fix the ladder so there are no gravity tricks,and the player can be able to stop mid climb and not slide back down. Or I could simply cop out and force people to press the use button to mount the ladder, and press use again to dismount.
Here is the result of my sleepless night:
- 4
5 Comments
Recommended Comments