Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: [Request / Listing] [GM6] Help with collision  (Read 1992 times)

0 Members and 1 Guest are viewing this topic.
[Request / Listing] [GM6] Help with collision
« on: April 21, 2006, 03:32:01 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 2690
I'm having a lil' trouble with collision... :P
I don't work with GM6 for a few months - and lost practice xP
Can someone tell me how to make my character with a 16x16 mask collide with a rock?
(Note: in case this helps (xP) I like to use depths - but still haven't got a lot of ways to work :\)
« Last Edit: February 24, 2012, 01:34:52 pm by Niek »
Logged
Re: [GM6] Help with collision
« Reply #1 on: April 22, 2006, 05:55:21 am »
  • You're the yellow bird that I've been waiting for.
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 242
This really depends on the walking system your using, but play around with these commands

Code: [Select]
position_empty(x,y)
place_free(x,y)
collision_point(x,y,obj,prec,notme)
collision_rectangle(x1,y1,x2,y2,obj,prec,notme)
collision_circle(xc,yc,radius,obj,prec,notme)
collision_ellipse(x1,y1,x2,y2,obj,prec,notme)
collision_line(x1,y1,x2,y2,obj,prec,notme)

you can set all x's and y's to a relative position such as "x-16"

Here is an example code that pretty much says, "If the player is holding down the left arrow key, and the place 3 pixels to his/her sprite is free then move him 3 pixels to the left. This excludes the commands to change animations an such though.
Code: [Select]
if keyboard_check(vk_left) = 1 then
{
  if place_free(obj_player.x-3,obj_player.y) then
  {
    obj_player.x -= 3;
  }
}
There are of course countless variations to this code based upon your movement engine.

Hope this helps  :P

EDIT: In my opinion the GM Help file is the most useful resource for coding. It lists all of the scripting commands, describes them, and gives examples of practical use. If it weren't for the GM help file, I'd still be using rm2k (>_<) So if this doesn't help, I highly suggest you study the help file.
« Last Edit: April 22, 2006, 05:59:23 am by brighteyes »
Logged
Re: [GM6] Help with collision
« Reply #2 on: April 28, 2006, 11:34:30 pm »
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 1141
Code: [Select]
if (character.x <= rock.x + rock.sprite_width && rock.x <= character.x + 16 && character.y <= rock.y + rock.sprite_height && rock.y <= character.y + 16)//OBS: The "<=" may have to be changed to "<", depending on when the script is executed.
{
  //collision exists
}
Logged
Pages: [1]   Go Up

 


Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved



Page created in 0.038 seconds with 40 queries.