Git Product home page Git Product logo

Comments (10)

henriiquecampos avatar henriiquecampos commented on August 11, 2024 1

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.

pixelprogrammer avatar pixelprogrammer commented on August 11, 2024

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.

henriiquecampos avatar henriiquecampos commented on August 11, 2024

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.

NathanLovato avatar NathanLovato commented on August 11, 2024

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.

henriiquecampos avatar henriiquecampos commented on August 11, 2024

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.

pixelprogrammer avatar pixelprogrammer commented on August 11, 2024

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.

NathanLovato avatar NathanLovato commented on August 11, 2024

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.

henriiquecampos avatar henriiquecampos commented on August 11, 2024

This edge case is fixed in 48b933e

So I think we can close this

from godot-beginner-2d-platformer.

NathanLovato avatar NathanLovato commented on August 11, 2024

@henriiquecampos Thanks. Could you use Close #... or Fix #... in your commits directly, at the end, to close the issues?

from godot-beginner-2d-platformer.

NathanLovato avatar NathanLovato commented on August 11, 2024

(in the future)

from godot-beginner-2d-platformer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.