Comments (10)
That's pretty much what we did before @pixelprogrammer , but as a general rule is better if each object handles their own logic, whenever possible, that's why we delegated the two outcomes of a stomp to their respective objects.
We've talked a lot of these kinds of situations in games: single event, multiple effects on different objects.
In general, you create an object that will carry the data to the users. For instance, that's what we do for Hit/Hurtboxes in gdquest/godot-platformer-2d, when they intersect we create a Hit object that both can access, pass data to and get data from. This way you create an object with the solo purpose of mediating these other two. You can check out the Mediator pattern to understand this concept better: https://refactoring.guru/design-patterns/mediator
from godot-beginner-2d-platformer.
It looks like it has to do with the area2d's being wider than the body of the collisionShape2d. Because Enemy detects the body to enter its area it might collide with the area and not the body, thus, allowing the player to bounce without the enemy dying.
from godot-beginner-2d-platformer.
This is not fixable, but rather tweakable, with the current approach.
One way to guarantee a sync between the enemy dying and the player bouncing is by creating a stomp object, based on the player's kinematic body's kinematic collision and pass this object to the enemy and the player when their areas intersect, regardless how they intersect, it could even be circle areas covering them, and let them handle their logic based on this.
This is because with the kinematic collision we can access data relevant for the stomp, like the normal of the collision and based on that perform the stomp with data synced. This won't be possible with just Areas, they only handle overlapping and overlapping is not enough for a nice stomp mechanic.
Nonetheless, this edge case is fixed at 48b933e
from godot-beginner-2d-platformer.
We had issues back when it used kinematic collisions as well. I don't remember what that was exactly, but it had to do with keeping the code simple for the tutorial.
Nonetheless, this edge case is fixed at 48b933e
Did you forget to push a commit?
from godot-beginner-2d-platformer.
I don't remember what that was exactly
Was because the logic was centralized in the Player and @razcore-art suggested to delegate the logic of killing the enemy to the enemy itself. Since the enemy couldn't detect a collision using its own KinematicBody (because its movement is just horizontal) we decided to go with Area2D.
Did you forget to push a commit?
I'm missing write access I guess.
edit: nevermind, git just forgot I was logged in
from godot-beginner-2d-platformer.
Question, as game development and tutorials can be rather tricky, one of the ways I delegated this task was having the player call methods of the enemy to issue a hit or stomp.
Since the area2d or body collide with the stomp area, you do get the enemies area2d or collision body passed through the signal for access. I have interfaces (I'm using C#), so I typecast the object to an interface like IStompable
if null
do nothing, if not then call a method that tells the enemy they have been stomped like gotStomped
, or something, and have that enemy do the rest like remove a hit point, or die if no hitpoints are left.
I am still relatively new to game development so I am not sure the best route to determine which objects manage the state, or call the state onto other objects in the gaming world, but this approach seems to work for me so far.
on a side note, the tutorials are some of the best so far for the Godot game engine. Much appreciated of the work you guys are doing 😎
from godot-beginner-2d-platformer.
I'm not sure there, as we don't use c#. In GDScript you use a callback, or duck typing: with has_method for instance
from godot-beginner-2d-platformer.
This edge case is fixed in 48b933e
So I think we can close this
from godot-beginner-2d-platformer.
@henriiquecampos Thanks. Could you use Close #...
or Fix #...
in your commits directly, at the end, to close the issues?
from godot-beginner-2d-platformer.
(in the future)
from godot-beginner-2d-platformer.
Related Issues (20)
- Consider how coin scoring is done HOT 3
- Remove Geometry2D.gd dependency
- Fix Level transition HOT 2
- Sometimes the player "stomps" but the enemy doesn't die HOT 6
- SceneTree.*_scene functions leave the game stuck After pressing the RetryButton, going back to the main menu, or reloading a scene in general, in Godot 3.1, the game gets stuck HOT 4
- Death counts reset when retrying
- IDK if I did this wrong but the game shows an empty screen in TestLevel
- Back to the menu does not work HOT 1
- Play and Quit button bug after returning to Main Menu HOT 2
- EndScreen wont Expand HOT 1
- Not Really a bug... HOT 2
- Portal Interrupted by Enemy Collision HOT 1
- MainScreen paused and Score persists on Play Again HOT 1
- MainScreen Menu Not Working HOT 1
- Issue: lose all score when retry level HOT 1
- This bug HOT 1
- Bug if back main menu and click button play HOT 1
- Bug HOT 1
- Godot 4 HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from godot-beginner-2d-platformer.