Dev Blog

Hi, this is the Stranded III development blog (see also Forum Thread, Comment Thread).

Overview (101 Entries)

Entry 99 - Controller & Ghosts - February 21, 2021

Character Controller
It's cool that Unity has a CharacterController but unfortunately it's quite limited (a character controller is used to move characters in the game world. Either based on user input or based on AI decisions).
Until now I've been using it for the player and it was okay. I also wanted to use it for AI controlled characters like wild animals but I quickly encountered weird behavior.
There seems to be no practical way (except for weird and dirty hacks) to prevent that character controllers can step on each other. I don't want animals to form stacks like the Town Musicians of Bremen. It looks weird and it would possibly allow them to overcome obstacles which they normally shouldn't be able to pass.
Moreover there are some other limitations which can't be controlled properly. Therefore I wrote my own character controller which gives me full flexibility and freedom. If it does weird stuff it's my own fault and I can hopefully fix it. If Unity's character controller does weird stuff I'm rather helpless because I don't have access to its source code.

Writing your own character controller is a surprisingly complex journey. My approach works now but it's still very limited.
Unity offers some nice functions like RigidBody.SweepTest or Physics.ComputePenetration but they all come with annoying limitations and issues.
Why do you need an instance of a rigidbody to do a sweep test? Why does the sweep test ignore colliders when you're already colliding with them? Why can't I test if two convex mesh colliders collide?
I understand some of the reasons behind these limitations but it's very annoying and time consuming to work around them.

Therefore I ended up with just doing a ton of raycasts to check for collisions.
I believe that this is what Unity's character controller also does internally.

Building Ghosts
When placing buildings you need to see what it will look like when they are finished.
Most games use so called ghosts to visualize unfinished buildings or buildings which are being placed. I guess they are called like that because they have no collision and because they are transparent in most cases.
I found a cool shader which is actually intended to render glass. I modified it a bit and now it's the perfect shader for my ghost buildings.

Placing a palisade wall:
IMG:https://stuff.unrealsoftware.de/pics/s3dev/buildingghost.gif

The ghost turns red when you can't build in the chosen location. If the location is valid you'll see a green ghost.
Note that the palisade wall seems to jump because an optional building grid is enabled.
The shadows move quicker than usual because I increased time progression speed for testing purposes.

Placing a camp fire:
IMG:https://stuff.unrealsoftware.de/pics/s3dev/ghost_campfire_pre.jpg

> Click for bigger version

Disqus

blog comments powered by Disqus