0 Favourites

How do I select single object?

  • Hi all. I have an event as follows,

    Every Tick

    When right mouse button is down

    'Build_Collision' Object is overlapping 'Block' Object

    Set 'Block' position to mouse.x mouse.y

    I'm trying to figure out a way to only select 1 'Block' object when the collision is overlapping. Any ideas? Ive only managed to create a big mess so far. Thanks

  • If I understand you correctly,

    You don't need "every tick". Try reversing your condition.

    Block object is overlapping Build_Collision

  • I didn't explain myself very well sorry.

    What i'm trying to do is, when the 'Build_Collision' overlaps more than one 'Block', only 1 instance of the 'Block' object is set the the mouse position.

    At the moment it selects all instances of the 'Block' object overlapping the 'Build_Collision'. I just need 1 at a time.

    I've tried a few things, but cant get my head around it.

  • You can use "Pick random instance" condition after overlap condition.

    Edit: Just realized this wouldn't work as this would pick new random instance every tick. You will need more comlicated set of events and conditions to pick only once.

    I'm not quite sure I understand what you are trying to do. Maybe it would be better to perform action when mouse button is clicked insteas of while pressed.

  • Yeah its a tricky one for me.

    Imagine you have some square blocks, when the mouse is down it creates an invisible object set to cursor position.

    When the invisible object overlaps the block, the block is set also set to cursor position. After the first block is set to mouse position, no further blocks are affected by the invisible collision.

    I've tried giving the collision object a variable called 'picked', when the block overlaps it, set the variable to 1. On release set it back to 0. This doesn't seem to work.

    ill gladly try an ideas.

  • Could you post your Capx file?

  • OK. Now I understand it better.

    You should give instance variable 'picked' for block (not for your collision object). Then when mouse is clicked use overlap and pick random instance conditions to pick one of the blocks that are overlapping the collision object. Set variable 'picked' to true for picked 'block'.

    Then make two separate events:

    'Block' is 'picked' -> Set 'Block' position to mouse.x mouse.y

    Mouse On button released -> 'Block' Set 'picked' to false

    The basic idea is to pick one block when mouse is clicked. Keep moving it to mouse position as long as the 'picked' variable is true. And finally set 'picked' variable false for all blocks when mouse button is released.

    Instead picking random you can pick nearest if it works better for your game.

  • Thanks! How would i go about selecting the closest instance of an object to the mouse cursor? ill give it a try this evening and let you know how it goes.

  • try using the system event pick by comparing, and then use when on mouse over uritem pick by comparing z index is greater then uritem.zindex that way will automatically pick the item u hover that is above

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • Sorted it!

    I was trying to cram too much into one event as usual. Having the block to 'Picked' on mouse down, and setting the position when block is 'Picked' was the way to go.

    Thanks a bunch.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)