Jump to content


Photo

Hexagonal Collision


  • Please log in to reply
1 reply to this topic

#1 ipq

ipq

    GMC Member

  • GMC Member
  • 34 posts

Posted 07 April 2012 - 08:38 PM

Hi. The last time I was bored, so I just tried to experiment. I made a hexagonal collision. I do not know whether anyone has done something similar but never mind. I made a script that checks the collision according to hexagonal shape. There are two variants. A vertical (stayng) and one horizontal (lying). If you did not understand, there is also an example. Here is a simple sample scripts how it works:

collision_hexagonal_ver(x,y,point_x,point_y,wsize,hsize,vecsize)
var sirka;
sirka=argument4- (((argument1-argument3)+argument5)/-argument6*argument4)* ((argument3-argument5)>argument1) -(((argument1-argument3)-argument5)/argument6*argument4)* ((argument3+argument5)<argument1);
if (argument0>argument2-sirka && argument0<argument2+sirka && argument1>argument3-argument5-argument6 && argument1<argument3+argument5+argument6) return 1 else return 0;
collision_hexagonal_hor(x,y,point_x,point_y,wsize,hsize,vecsize)
var vyska;
vyska=argument5 -(((argument0-argument2)+argument4)/-argument6*argument5)* ((argument2-argument4)>argument0) -(((argument0-argument2)-argument4)/argument6*argument5)* ((argument2+argument4)<argument0);
if (argument0>argument2-argument4-argument6 && argument0<argument2+argument4+argument6 && argument1>argument3-vyska && argument1<argument3+vyska) return 1 else return 0;
The complete version of this manual is also in the downloadable file:
http://www.ourupload...on.zip[Updated]
GML file contains the manual and GM81 as an example of how it works(in Lite version work too).
Style guide how I did it at gmlscripts.com, I like the style, so I use it too.
EDIT: Updated scripts, thanks slayer 64..

Edited by ipq, 01 June 2012 - 08:53 PM.

  • 0

#2 slayer 64

slayer 64

    Slayer of gingers

  • GMC Member
  • 3891 posts
  • Version:GM:Studio

Posted 03 May 2012 - 12:29 AM

i made collision_hexagonal_ver faster
/*
**  Usage:
**      collision_hexagonal_ver(x,y,point_x,point_y,wsize,hsize,vecsize)
**

    0 x
    1 y
    2 point_x
    3 point_y
    4 w
    5 h
    6 v

**  Arguments:
**      x,y              standard position, would be checked to collision(i.e. mouse chcek)
**      point_x,point_y  collision position, attention, started to centerpoint
**      wsize            collision width
**      hsize            collision height
**      vecsize          collision edge
**
**  Preview:
**
**    vecsize
**      /\
**     /  \
**    +---+
**    |   |
**    | . |hsize
**    |   |
**    +---+---vsize
**    \  /
**     \/
**
**   . - point_x,point_y
**
**  Created by ipq.
*/
var a;

if argument1<argument3-argument5-argument6 return 0
if argument1>argument3+argument5+argument6 return 0

if argument1<argument3-argument5
{
    a=argument4+(((argument1-argument3)+argument5)/argument6*argument4)
}
else
{
    if argument1>argument3+argument5
    {
        a=argument4-(((argument1-argument3)-argument5)/argument6*argument4)
    }
    else
    {
        a=argument4
    }
}

if argument0<argument2-a return 0
if argument0>argument2+a return 0

return 1

i improved everything a little
ax=room_width*.25
ay=room_height/2
aw=24
ah=16
av=32

bx=room_width*.75
by=room_height/2
bw=32
bh=32
bv=32

draw_set_color(merge_color(c_red,c_lime,collision_hexagonal_ver(mouse_x,mouse_y,ax,ay,aw,ah,av)))

hexagon_draw_ver(ax,ay,aw,ah,av)

draw_set_color(merge_color(c_red,c_lime,collision_hexagonal_hor(mouse_x,mouse_y,bx,by,bw,bh,bv)))

hexagon_draw_hor(bx,by,bw,bh,bv)

/*
    hexagon_draw_ver(x,y,w,h,vsize)
    
    0 x
    1 y
    2 w
    3 h
    4 vsize
*/


draw_line(argument0,argument1-argument3-argument4,argument0-argument2,argument1-argument3)
draw_line(argument0-argument2,argument1-argument3,argument0-argument2,argument1+argument3)
draw_line(argument0-argument2,argument1+argument3,argument0,argument1+argument3+argument4)

draw_line(argument0,argument1+argument3+argument4,argument0+argument2,argument1+argument3)
draw_line(argument0+argument2,argument1+argument3,argument0+argument2,argument1-argument3)
draw_line(argument0+argument2,argument1-argument3,argument0,argument1-argument3-argument4)

/*
    hexagon_draw_ver(x,y,w,h,vsize)
    
    0 x
    1 y
    2 w
    3 h
    4 vsize
*/

draw_line(argument0-argument2-argument4,argument1,argument0-argument2,argument1-argument3)
draw_line(argument0-argument2,argument1-argument3,argument0+argument2,argument1-argument3)
draw_line(argument0+argument2,argument1-argument3,argument0+argument2+argument4,argument1)

draw_line(argument0+argument2+argument4,argument1,argument0+argument2,argument1+argument3)
draw_line(argument0+argument2,argument1+argument3,argument0-argument2,argument1+argument3)
draw_line(argument0-argument2,argument1+argument3,argument0-argument2-argument4,argument1)

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users