[IGNORE, I’M LITERALLY JUST RANTING ABOUT HOW I SOLVED MY WORST PROBLEM TO DATE, ON A TOPIC I OPENED ON MY OWN]
Rant about my swimming state, part 2 (this is completely pointless, but I’m ranting here because fixing this is not perfect, and was aggressively harder than I thought it to be)… So here’s what I did
In order for me to get on a boat, I used a RangeFinder, just like any other solution like Resource Gathering, Crafting Tables, Conversation with NPCs, etc…
Now, getting on to the boat from land was no big deal. Just find the boat, hit the “F” button and get on the boat, and everyone is happy
Getting on to the boat from the ocean, however, was a complicated one, and here’s why:
When I was developing my swimming state, I had 4 different states:
- The Swimming State. In this state, you’re just swimming and turning around, no biggie
- The diving state (using the control button. Not a seperate state, but it has it’s own buttons in the Input Controller… but it’s taken care of in the Tick of the Swimming State. In short, you can dive underwater by holding the control button with this one)
- The reviving state (using the space bar button. Similar to diving state, it’s taken care of whilst swimming. However, this one was a complex one, because when you’re reiviving, the player doesn’t know when to stop reviving. This means that I had to place an invisible box collider on top of his head when he’s reviving, to ensure he doesn’t revive his way to space, and it will get deactivated when the space button is let go of… it’s only accessed from the swimming state as well, so this makes life easier when you’re out of the swimming state. The big problem is, because we were brutally stopping him with that box, when you get off driving the boat, he will want to try to fly into space to cover up for what reviving did to him)
- And finally, the player sprint swimming state. Again, taken care of whilst swimming, and has its own individual buttons (left shift for my case, whilst swimming only)
All these states have their animations taken care of in a blend tree. I’m not getting into this here
So my problem was, as mentioned before, because my revive to entering a boat is not a friendly solution, I had to think of a different one. So here’s what I did (drumrolls please):
Remember when I told you earlier that the RangeFinder finds anything? In order to find the boat, you need a boat box collider on it. So what I did, was use that box collider’s trigger boolean to mess with it.
-
First, I developed a boolean function, and it checks if the player is close to the boat or not, by getting the Vector3 distance between the player and the boat, and compare it to a threshold I setup as a hard-coded 2f (because any higher than that, and you’ll end up immediately getting back on to the boat the moment you jump off the boat into the ocean), and if he is, we will act accordingly.
-
If the player was reviving and he was close to the boat (check 1, the “IsCloseToBoat()” function), turn that trigger off so that it becomes an invisible box collider. That way, he won’t be able to get close and collide with the boat’s colliders, or enter the boat when reviving. These were the two main reasons why the player would fly to space when he gets off the boat driving state that he either accessed from colliding with the boat’s mesh collider, or from entering from his reviving state
-
If he wasn’t reviving, I developed another function that AUTOMATICALLY gets the player to get on the boat when he’s close enough. That way he will have zero chances of colliding with the boat and somehow ending up flying in space
-
Unfortunately I can’t think of a solution that does all of this in the Tick method, so I used an event that was subscribed and unsubscribed to in the Enter and Exit states of the Swimming state of the player
And that’s about it…
I have to mention though, this is all a nightmare because the Boat’s mesh collider was a terrible one, so I had to use invisible planes and brutally force the player to stand on it when he drives the boat. I’m sure that would’ve been easier if that mesh was cleaner
Is the solution perfect? Probably not, because getting it all done in Tick would’ve been in ideal. But hey, I’m more than happy to get my players to step back a few steps and come back without reviving to get on the boat than have to deal with that annoyingly hard bug…
Thanks for reading my rant that was placed on the wrong topic
Just do me a favor and don’t try diving under the boat and then mounting it… it’ll glitch out on jumping, and you’re just nitpicking at that point in time. I won’t fix that anytime soon, my brain is steamed out after that one (although expanding the y-axis of the box collider, and an or statement on a function, seems to get rid of that one… I ended up fixing it anyway )