Phazorknight / Cogito

Immersive Sim Template Project for GODOT 4
MIT License
865 stars 98 forks source link

Making an object throwable and support for physics objects? #182

Closed PeterD23 closed 5 months ago

PeterD23 commented 5 months ago

Hi, so I downloaded the template to try and retrofit my existing game mechanics and discovered some issues:

When picking up a CogitoObject, despite there being a "throw" method implemented, it behaves as a drop instead. My assumption would have been there would be a keybind to drop (interact) and then a keybind to throw (fire) but it would seem that throw and drop are used interchangeably.

Physics objects don't seem to work properly, the player seems to have infinite strength and can push physics objects around regardless of their mass, which means that making something like a climbable box appears to be impossible unless the object is static.

Phazorknight commented 5 months ago

Hello and welcome.

Re: Throwing: How this was handled changed quite a bit since the first implementation, so some legacy naming is still in the code. You're not the first to bring this up, and it shouldn't be too difficult to implement actual throwing like you mention it (there's actually already a throw-strength variable in place). I can't commit an ETA at the moment, though.

Re: physics objects This is heavily dependent on a few factors. The box in the laboratory scene works well to be carried around and then jumped upon. I haven't encountered an issue of it being pushed around like it has no mass. Maybe you could open a separate issue with a quick video of what's happening? Overall most RigidBody3D's actually seem to inert/heavy when the player pushes against them (as I quickly tested with the potions in the laboratory scene.

PeterD23 commented 5 months ago

Hi, appreciate the response!

So for the throwing issue I was able to tweak the code by adding a function that just applied a throw vector to the object based on the throw strength so I guess that resolves my first problem!

As for the physics objects, it appears the one I had issue with was due to Collision Layer 1 being disabled after comparing the attributes between the existing system I had to the one Cogito uses. By enabling the layer I can now climb atop my boxes, but now the box wont move when pushed up against it which seems to be by design from testing the demo scenes.

Would it be possible to implement a system where objects can be pushed around by the player if they're light enough or the player is strong enough? My thinking for this was something like the original Deus Ex (2000) where you could push around small crates by bumping up against them.

Phazorknight commented 5 months ago

So I've just pushed an update for these two things in https://github.com/Phazorknight/Cogito/commit/f8d8d0e72ebb6b817390a1de67af743f9653cf4c

These are very simple implementations but should be good enough and can be easily tweaked.

Throwing Any object with a carryable component can now be thrown if the player uses the action_primary input (left click/right trigger). The throw_power can be set on the player interaction component.

Pushing The player can now push RigidBody3D objects. The "push force" can be set on the player.gd and takes object weight into account, meaning that if an object is too heavy, the player will not be able to push it around. This is using apply_central_force, so the usual Godot Physics shenanigans can happen, but enable you to have crates that can be pushed around by running into them.

Let me know if there's anything else or if this closes this issue.

PeterD23 commented 5 months ago

Awesome, thank you so much! I'll have a play around with them tomorrow and if I run into any issues I'll see what I can do to resolve them.