collision required for diablo like game?

Blitz3D Forums/Blitz3D Programming/collision required for diablo like game?

matthews_30(Posted 2006) [#1]
well guys,

i am trying to create a diablo like game (it is only 2D graphics and i am using Blitz3D), i have the graphics (main character, 3 enemies, walls, etc.) but i dont know how to do the following:

1. enemies walk freely and attack the main character when he is near a certain distance of the enemies.

any idea or basic sample code?


n8r2k(Posted 2006) [#2]
you need to find the distance between the player and enemy with the distance formula:
square root((x2-x1)^2 + (y2-y1)^2)
if this comes out to be less than a certian distance, make the eniemy attack

then make some artificial intelligence for when the player is far enough away.


Jeppe Nielsen(Posted 2006) [#3]
This example might also help, it keeps enemies from sliding into each other:
http://www.blitzbasic.co.nz/codearcs/codearcs.php?code=983


n8r2k(Posted 2006) [#4]
Jeppe: havent looked through that code completely, but he said hes doing 2d game not 3d.


matthews_30(Posted 2006) [#5]
the code posted "Jeppe Nielsen" is very close to what i need, but how can i make it work for a 2d game? it is a little bit difficult to understand the creatureUpdate() function.

maybe if somebody help me to understand it i can translate to 2D.


matthews_30(Posted 2006) [#6]
or maybe i can understand better if somebody tell me what the "L" is doing and what is the concept behind the translate entity because i read about it but i still can not the this code is using it :(


octothorpe(Posted 2006) [#7]
L (length) is the distance between the character and the target.

(dx,dy,dz) is a vector describing the direction and distance from the character to the target. The magnitude of this vector is determined (L) and the vector is then divided by it; this "normalizes" the vector - its magnitude is now 1. The vector is multiplied by the character's speed (c\vel, which is named incorrectly and should be called c\speed!) then added to the character's position with TranslateEntity.

All this means that the character will move toward the target by a distance of c\vel.


tonyg(Posted 2006) [#8]
A little FSM might help.


Sir Gak(Posted 2006) [#9]
tonyg: That was a great article. Thanks for referring to it, and especially hats off to morduun for posting it.


matthews_30(Posted 2006) [#10]
now the question is how to add the distance formula posted by "n8r2k" in the "Jeppe Nielsen" post?

i dont want all the guys run to me, only the ones that are closer to me (certain distance).