Open malcolmriley opened 5 years ago
We've got a bit of an issue on our hands regarding the current Squirrel player movement implementation. Here's the breakdown:
Rigidbody
attached to its parent object. See documentation here.Rigidbody
attached to its parent object. See documentation here.CharacterController
. These collision events only fire on scripts attached to a parent object with a CharacterController
attached. Theoretically we could do all our different branch logic in PlayerController
but I'd personally be against it; in my opinion branch behavior should be attached to the branch prefab and not scattered wherever it fits.Rigidbody
to the Squirrel, but the Squirrel's movement is controlled by the script directly, and not by physics as seen here, and some other places in PlayerController
. Thus we cannot currently enable physics on the Squirrel without making some internal changes to the way player motion is handled.CharacterController
) so we can't just turn our existing colliders into Triggers, because we need them to interact physically.The fundamental issue is that the current Squirrel movement implementation is incompatible with physics.
The current workaround is to attach a second capsule collider to the Squirrel, and a kinematic Rigidbody
that doesn't respond to gravity (Since we can't use physics on the Squirrel), as well as secondary trigger-only colliders on the branches. Thus, the branches can respond to Trigger collision events without interfering with the way the Squirrel's movement works currently. Only time will tell if this is ends up being an effective long-term solution, so I'm documenting my reasoning for it now so that when we all forget why everything was the way it was we can look back and hopefully piece it all together again.
Thank you for looking into this.
First: I would like to use your "secret third flavor" of collision detection because it means we can keep our existing character controller code. All of my playtesters said that the player controls feel very solid and I dont want to backtrack and lose that.
Second: when I was building the character controls I looked into and tried using a ridgidbody but it didnt "feel" right and I ended up using the character controller because of this.
Therefore I think there are two ways we can go about this.
1) I think an alternative would be to create a new script and attach it to the player and access the character controller through this to do our physics. It would be using your "secret third flavor" but also keep branch logic in its own file without interfering with the player controller script.
2) alternatively if you want to keep the scripts attached to the branch prefabs you could theoretically access the player from the scripts on the prefabs
if you have questions or wish to discuss this you know how to reach me :)
Well, I think it would probably be possible to recapture whatever magic we have using the CharacterController
with a physics-based approach but then again I haven't actually tried it, so maybe not.
Compromise counterproposal:
CharacterController,
don't use Rigidbody
, etc.CharacterController
's collision events. This script then calls some as-yet-unimplemented methods on the Branch the squirrel collided with.GameObject
as parameter and maybe some other things too, they can then affect the SquirrelPros:
Cons:
PlayerController
internals anyways, particularly all the Vector3
s we're using to track motionNot ideal in my opinion, but then again, is anything ever?
Ideally, this will be implemented as a number of prefabs, wherein common behavior is implemented in a scripts for the simple type, and specific behavior is implemented via a script inheriting from that base type.