Jump to content


Photo

Check for collision when pressing key


  • Please log in to reply
4 replies to this topic

#1 larreeh

larreeh

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 10 July 2012 - 01:17 AM

I have an object called "mainPlayer", and an object called "dispenser". When I press a key and these two items are colliding, I need to increase "itemVariable" +1. How can I do this?

Thanks in advance.

Edited by larreeh, 10 July 2012 - 01:18 AM.

  • -1

#2 ZyklonMiraj

ZyklonMiraj

    Gorkhali

  • GMC Member
  • 313 posts
  • Version:Unknown

Posted 10 July 2012 - 01:34 AM

collision event of dispenser with mainPlayer
if keyboard_check_pressed(vk_space)//this could be any thing.
{
itemValue+=1
}
for ordinary keys from A-Z and 0-9 u must do keyboard_check_pressed(ord('A')) etc.

Edited by ZyklonMiraj, 10 July 2012 - 01:35 AM.

  • -1

#3 GMKn00b

GMKn00b

    GMC Member

  • GMC Member
  • 150 posts
  • Version:Unknown

Posted 10 July 2012 - 08:14 AM

So on the "key press" event (the button you have to press) :GM132: or :GM128:

//Have:
if position_meeting(x,y,obj) {itemValue+=1}

  • -1

#4 larreeh

larreeh

    GMC Member

  • New Member
  • 5 posts
  • Version:Unknown

Posted 11 July 2012 - 12:42 AM

So on the "key press" event (the button you have to press) :GM132: or :GM128:

//Have:
if position_meeting(x,y,obj) {itemValue+=1}


Thank you. Would you mind explaining where do I enter my two variables? that need to collide? thanks again!

Edited by larreeh, 11 July 2012 - 12:43 AM.

  • -1

#5 GMKn00b

GMKn00b

    GMC Member

  • GMC Member
  • 150 posts
  • Version:Unknown

Posted 11 July 2012 - 03:09 AM

First make sure the code is in key press of obj_mainPlayer
Spoiler


Two variables? You mean obj_mainPlayer and obj_dispenser?

obj_dispenser would be put in the brackets (you don't need to put the mainPlayer 'cause the code is in it not a controller object)
if position_meeting(x,y,obj_dispenser) {itemVariable+=1} 
//once you press the key it executes this code which checks if you're colliding with obj_dispenser and if yes then it will increase itemVariable by one

Hope that's what you were asking for :whistle:

Edit:

Woops forgot, change itemValue to itemVariable, I've change the code above so it should be fine

Edited by GMKn00b, 11 July 2012 - 03:20 AM.

  • -1




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users