https://github.com/Chabinka/Fragsurf-Character-Controller
A few users were interested in having their own surf in Unity so I thought I'd share.
SurfPhysics.cs contains functions ported from the hl2 source.
SurfController.cs simply puts those functions to use, taking in something that implements ISurfControllable
SurfCharacter.cs is a monobehaviour component which implements ISurfControllable and passes itself to a SurfController
MovementConfig.cs contains various values which affect movement/acceleration
Most of this was quickly slapped together for testing and debugging, and isn't even finished, so be sure to take what you need from it and implement it in your own way.
There are some interpenetration issues. BoxCollider tends to catch ramp bugs, but CapsuleCollider is pretty smooth. Enabling Physics.queriesHitBackfaces seems to reduce the possiblity of ramp bugs.
Damn man, thanks for sharing.
Ha, surfing in Unity, that'd be fun to play, someone should make a dedicated game for surfing really.
I had that exact idea a year or two ago and spent some time reimplementing surfing and bhopping in Unity before moving on to other stuff lol
Glad to see someone put it together in a more cohesive and presentable way. Cheers OP
Nice.
How does your code handle stairs?
There's no logic for stairs. It's just air acceleration, surf, and simple collision checking
I see.
Have you found a solution for stairs?
I managed to come up with a working solution. I'm going to try and duct tape it to your system and see how that works out. If it works I'll share it with you guys.
Would it work all the same to have a ramp as a collider for the stairs?
Not quite, there's nothing for walkable slopes either. Walking up a slope slows movement down, walking down a slope causes it to bounce. Normally you'd sweep test down to figure out where the ground is, and snap the player's Y to the hit position, then it would work just fine.
My old solution took the player's position, incremented it by step height, sweep tested downwards by step height, and used possible hit info to adjust the player's Y position. If the sweep test starts inside something or fails, then there's probably a wall at the player's head height and no adjustments are made. It might be helpful for the sweep test to start ahead of the player, so position + velocity * deltatime
Can you reupload?
I'll upload it here when I get some time
Sorry, you need to Log In to post a reply to this thread.