Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Physics #18

Open
Vrekt opened this issue Oct 18, 2017 · 20 comments
Open

Physics #18

Vrekt opened this issue Oct 18, 2017 · 20 comments

Comments

@Vrekt
Copy link
Owner

Vrekt commented Oct 18, 2017

BTW: I'm going to assign more people to this once they accept.

I'm wanting to add basic physics to the game. Something easy and simple to use. If you have an ideas please share them with me below.

Something like gravity would be simple enough. I'm thinking:

BasicPhysics.handleGravity(myEntity, direction, speed);
or something where the entity implements a physics class and it handles it automatically. I'm not sure still thinking about how to implement it.

@Vrekt
Copy link
Owner Author

Vrekt commented Oct 18, 2017

Basic velocity class -- improve later, thanks minz
https://hastebin.com/edavijinif.java

@rickbau5
Copy link
Collaborator

Cool, I’ll take a look

@minz1
Copy link
Collaborator

minz1 commented Oct 18, 2017

2nd revision: https://hastebin.com/azilisasok.java

This doesn't take into account collisions, but gravity should be accounted for.

@rickbau5
Copy link
Collaborator

So I'm not sure that Velocity needs to be a separate class. Velocity is really just a property like position x and y and is only meaningful in that context so I think it makes sense to have it part of the Entity class. Entitys are going to be the only things that really use it as typically entities are the things which are non static, i.e. moving.

Thoughts?

@minz1
Copy link
Collaborator

minz1 commented Oct 18, 2017

Yeah, I've been mulling over that too. It's probably better that way, actually.

@rickbau5
Copy link
Collaborator

Sounds good, i'll throw something together real quick as a proof of concept.

@Vrekt
Copy link
Owner Author

Vrekt commented Oct 18, 2017

I agree, btw i updated the tutorial what do you guys think. I need to include more but its the basic idea.

rickbau5 added a commit that referenced this issue Oct 18, 2017
@rickbau5
Copy link
Collaborator

rickbau5 commented Oct 18, 2017

Alright, pushed something to basic-physics branch. It just adds entity velocity. Sorry it took a bit, had to re-setup my dev environment.

Example.

Obviously it's very simple at this point. But it's just to get the ball rolling. I was debating whether the world should handle adjusting velocity of entities based off of gravity or the entities themselves doing that. If it was done this way, then i'd propose adding a affectedByGravity flag to the Entity class, and add an implementation for updateEntity in the World class. Or there could be a new updatePhysics method. Many game engines differentiate between logic updates and physics updates.

@Vrekt
Copy link
Owner Author

Vrekt commented Oct 18, 2017

Very nice I like that. I think entities should handle their own velocity stuff. Could cause problems with performance if the world is handling everything maybe.

@minz1
Copy link
Collaborator

minz1 commented Oct 18, 2017

My main concern is with how collisions would work. That's the largest problem with the physics. Any ideas?

@rickbau5
Copy link
Collaborator

rickbau5 commented Oct 18, 2017

@Vrekt maybe entites should handle setting their own velocity and what not, but then a centralized thing handle moving them around and checking collision like @minz1 brought up. Really if we want collision i think the only way to handle it is to have one class responsible for moving entities and checking collision. Otherwise the burden would be on the implementer for handling collision.

@minz1 to your question though, there's a BoundingBox class already which could be used to check collision.

Another thought - we need to look into adding the delta time to logic/physics calculations. From this article under point 1.2:

any game that has even basic physics (such as a platformer with jumping) will have wildly different behavior based on the frame rate.

Having delta time and including it in physics calculations solves that

@Vrekt
Copy link
Owner Author

Vrekt commented Oct 18, 2017

Yeah Ill make a class soon that handles collisions where the user can call the methods within it when updateEntity is called.

@minz1
Copy link
Collaborator

minz1 commented Oct 19, 2017

@rickbau5 That sounds like the best way to me. I'll write a quick outline of how that could work and maybe start committing something basic and working to the physics branch when I get the time.

@thinkier
Copy link
Collaborator

Oh hi I'm a bit late to the party.

@thinkier
Copy link
Collaborator

thinkier commented Oct 23, 2017

Added a basic gravity object to basic-physics#3975b89. The object can probably expanded upon to handle all changing velocities based on gravity. - Or maybe motion can be another problem in another class.

@minz1
Copy link
Collaborator

minz1 commented Oct 23, 2017

I was under the impression that Gravity and such would be done under Entity.

EDIT: Also, for the way that object is written, perhaps Velocity or Force would be a better name.

@rickbau5
Copy link
Collaborator

I agree with @minz1 - that’s a velocity class disguised with the name gravity 😉 this class could be used as a property of entity, so this works for me.

@thinkier
Copy link
Collaborator

thinkier commented Oct 24, 2017

🤔 Fair enough. I would be inclined to name it Force and then make Direction point to something else, as motion isn't exclusively up/down/left/right/origin.

@thinkier
Copy link
Collaborator

thinkier commented Oct 24, 2017

Changed the Velocity class to point to a x and y instead of a Direction at b5b1c44

@rickbau5
Copy link
Collaborator

Want to make a merge request? You can actively continue to work on the branch but it would be a better place to have these conversations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants