[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/agdg/ - Amateur Game Development General

AGDG - The Board

Catalog

8chan Bitcoin address: 1NpQaXqmCBji6gfX8UgaQEmEstvVY7U32C
The next generation of Infinity is here (discussion) (contribute)
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Oekaki
Show oekaki applet
(replaces files and can be used instead)
Options
dicesidesmodifier
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, swf, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 5 per post.


Welcome to AGDG, have you ever made a game?
See also: /ideaguy/ | /vm/

File: 1439946362799.png (53.7 KB, 348x209, 348:209, 4384319.png)

d46fce No.21036

How should I distinguish collision between different types of entities? In other words, after I've determined that two hitboxes are intersecting, what's the best way to determine what should happen next?

Each combination of colliding entities could do different things. For instance, if a bullet hits a character, the bullet should disappear and the character should take damage; but if two characters walk into each other, they should block each other from moving further. Another example could be if a character walks onto a moving platform, the player should be carried by the platform; but a bullet should just pass through the platform.

How have you handled these interactions?

6d0a4a No.21041

switch (collision.type)

{

case("enemy"):

/* character loses health, maybe his position moves back or something */

case("impassible")

/* character can't move in that direction */

etc

etc

}


7f14bf No.21045

Just do exactly what you said.

Have a different byte-sized type ID for every object and when an object checks its collision code, it sees what kind of object it hit, and behaves accordingly


6b3432 No.21077

File: 1440024897856.gif (868.83 KB, 640x360, 16:9, 1413247726668.gif)

>>21041

>using strings when you want named identifiers

>switching on strings

Oy vey, remember the 6MB you're burning.

Use enums you pleb, or constants, or #defines, or whateverthefuck your language has.


ee6abb No.21079

>>21077

it's pseudo code, dipshit


d46fce No.21084

A switch statement isn't dynamic or data driven. Even if I wanted to hard-code everything, the switch statement is also not very scale-able.


ee6abb No.21087

>>21084

how many different collisions do you expect to occur in your game?


6b3432 No.21092

File: 1440073140072.jpg (57.61 KB, 960x479, 960:479, 1439740962354.jpg)

>>21079

It's pseudocode that switches on strings. That takes more effort to write than pseudocode which doesn't, you went out of your way to do so.


switch (collision.type) {
case(ENEMY):
//lose HP, &c.
case(IMPASSABLE):
//push back opposite to movement vector until not colliding
}

>>21084

It is scriptable, in the following example each thing that can collide has a number associated with it ('type' in the latter example), that number is a description of exactly how it collides. You could load those from a config file like the following:


grass
brick_wall_0 IMPASSABLE
brick_wall_1 IMPASSABLE
brick_wall_2 IMPASSABLE
teleport_circle TELEPORT
teleport_wall IMPASSABLE TELEPORT
castle_guard_0 IMPASSABLE ENEMY
teleporting_slime ENEMY TELEPORT //teleports you when you collide with it
//&c

As for scalability you don't need a branch for each thing that can collide, just handle the general cases separate from the specific cases.

The following pseudocode only handles collisions between the player (player) and something else (other). It's easy enough to generalise.


collision_descriptor type = other->collision_desc;

if (type & ENEMY)
other->attack(player);

if (type & IMPASSABLE)
while (colliding(player, other))
player->move(player->movementVector, -1);

if (type & TELEPORT)
player->teleport(other->destination);

>>21087

He probably thinking of handling each specific case separately for some unholy reason. In which case it would be the number of different things that can collide squared. With just a thousand separate things he would need a million branches if he took that approach.

Obviously he ought to handle cases generally.


295594 No.21305

>>21084

If, when the player collides with an object, instead of acting on a switch statement, it calls code from that object.

For example:

void OnCollisionEnter (Collision collision)

{

collision.HandleCollision(*Player);

}

Every object would have a HandleCollision function that it would call. It would be able to do whatever you wanted to the player through the object itself.

Slightly more work, but infinitely expandable.


790c26 No.21312

I had this problem a day ago.

here's my algorithm to deal with it.

1. check if theres a bounding box collision. if so continue.

2.check if you're closer to collide with the x axis or y axis.

3.if x < y, there force, x is closer. then move back the player to where you want him to go on the x axis.

4.if x > y, there force y is closer.do the same on the Y axis.

5.now the trickiest part is if x == y. youle find a way. my way was quite ugleir with this one. but what I did is I moved the player back to his previous pistion and move the y axis and x axis individually and cheked if one moved and the other don't, would there be a collision? if yes, fuck the other and do one that could collide.

I pretty much have a e bounding box collision function(step 1) and resolvecollision function(step 2,3,4,5).

and use it like that:

if(player.collisionWith(enemy))

player.resolvecollision(enemy);

If I wanted the player to die I would have created a function called: player.getKilledby(enemy);


295594 No.21314

>>21312

Try this for determining where the collision occurred.

https://youtu.be/xqzvb1epaIQ


790c26 No.21315

>>21314

that's one well made video! If only there could be more video like that instead of people talking slowly in front of their code for 20 min.

I might not use it since my shit kinda work and im quite hostile to change code that work just fine.

But whyis it unlisted(the video)?


295594 No.21317

>>21315

It's from one of my college courses shhhh


8f971c No.21322

>>21317

so ur saying some professor from ur college made this?


790c26 No.21325

>>21317

c-can you give me t-the powerpoint f-file if t-there's one




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]