T2D Tutorial Mouse Object Selection and Moving
by Matthew Langley · in Torque Game Builder · 04/06/2005 (11:41 am) · 17 replies
About the author
Was a GG Associate and then joined GG in 2005. Lead tool dev for T2D and T3D. In 2011 joined mobile company ngmoco/DeNA and spent about 4 years working game and server tech. 2014 joined startup Merigo Games developing server technology.
#2
Good choice and looking forward to part#2. :)
- Melv.
04/06/2005 (11:59 am)
Object picking is so very easy and very powerful in T2D so I'm really glad that you've focused on explaining how to utilise it properly people.Good choice and looking forward to part#2. :)
- Melv.
#3
Your definately right Melv, you set it up too easy lol... at first I was a bit affraid to attempt it (back when I first attempted it that is)... but out of the whole tutorial the object picking part is at most 2- 3 lines lol... I love it :)
After doing it this simple way I wanted to try and do it a way where it wouldn't use setPosition so that movement could be more accurately applied to an in game action (so it can be set up to not bypass collision and physics) though your overlap checks are impressive, even with setPosition you have to move quick to bypass it
04/06/2005 (12:04 pm)
Thx JamesYour definately right Melv, you set it up too easy lol... at first I was a bit affraid to attempt it (back when I first attempted it that is)... but out of the whole tutorial the object picking part is at most 2- 3 lines lol... I love it :)
After doing it this simple way I wanted to try and do it a way where it wouldn't use setPosition so that movement could be more accurately applied to an in game action (so it can be set up to not bypass collision and physics) though your overlap checks are impressive, even with setPosition you have to move quick to bypass it
#4
Oh wait... keep the mouse coords in a global var so that the last position is recorded. Stupid question. :-p
Is there a cleaner way to do this, though? Something like a getMousePosition() or something to that effect?
04/06/2005 (12:25 pm)
Melv's not kidding about mouse picking being easy to set up. :) The only thing I had a question about vis a vis mouse tracking was if there was a way to track the mouse position even if it wasn't moving?Oh wait... keep the mouse coords in a global var so that the last position is recorded. Stupid question. :-p
Is there a cleaner way to do this, though? Something like a getMousePosition() or something to that effect?
#5
Now to get rid of school so I can work on T2D :P
04/06/2005 (9:06 pm)
Thank you once again for your work Matt L. Your tutorials have really helped me and I'm looking forward to this one a lot :)Now to get rid of school so I can work on T2D :P
#7
04/07/2005 (11:48 am)
Yes picking rocks the house in T2D. When I had to do picking for the first time in T2D during my GID I was blown away by how easy it was. took me all of about 30 seconds with a small snippet from King Bob and I was up and running. Couldn't possibly be easier!
#9
04/09/2005 (5:44 pm)
This last part 3 covers a way to keep track of some debug information :)
#10
04/09/2005 (5:51 pm)
I'm working through it now. Mostly because it drives my wife nuts
#11
04/09/2005 (8:58 pm)
Lol... then I've succeeded in my goal!
#12
It does however give me a great resource on how to go about these things for my own games. And that alone is priceless
Edit:
I also may have misssed a step. So I'll go over it more later.
Moving on to 3 soon enough :)
04/10/2005 (2:39 pm)
Works good matt. Although there are some wierd affects with picking and droping and picking up again. More so in the second example.It does however give me a great resource on how to go about these things for my own games. And that alone is priceless
Edit:
I also may have misssed a step. So I'll go over it more later.
Moving on to 3 soon enough :)
#13
04/10/2005 (11:15 pm)
If theres an error feel free to post your code and the problem... I usually create a fresh copy as I create the tutorials, that way I can ensure as little error as possible, though its definately possible I put the wrong thing in the tutorial file lol, I usually go pretty quick :)
#14
I did not check my code yet since I am at work. I assume by it's behavior that I am missing something on its mouse up.
What happens is that I grab the object and move it but when I try to grab it again it doesn't do anything. If i click the mouse on a empty spot and click the box again it will move the box to the empty spot where I Just clicked. So I am obviously not releasing the object right.
04/10/2005 (11:31 pm)
Whenever I do tuts I end up copying my existing folder. I got in the habbit of putting everything in functions. That way I can just comment out the function calls and I don't have to worry about them messing with the tut I'm working on.I did not check my code yet since I am at work. I assume by it's behavior that I am missing something on its mouse up.
What happens is that I grab the object and move it but when I try to grab it again it doesn't do anything. If i click the mouse on a empty spot and click the box again it will move the box to the empty spot where I Just clicked. So I am obviously not releasing the object right.
#15
Your probably right... I'm pretty sure the final result works, tested it a few times... the complex moving method is what I used in my GID
04/10/2005 (11:34 pm)
Ahhh... a very good habbit to get into... ohh so hard to get into good habbits after you've already built bad ones lol... you'll like the third one... its pretty simple, much quicker than the first two...Your probably right... I'm pretty sure the final result works, tested it a few times... the complex moving method is what I used in my GID
#16
04/16/2005 (3:38 pm)
Heya Matt, not sure how often you check the resource page for the tuts, but I had a suggestion for the mouse picking tutorial. Instead of an isSelectable flag, the pick commands allow you to specify a layer and group mask, so that may be an easier and possibly tidier way of doing things. That way you can keep your selectable objects in their own group, or on their own layer.
#17
and thanks for suggesting that LoTekK... constructive suggestions like that are more than welcome... always trying to find the best way :)
04/21/2005 (7:42 pm)
Btw to on lookers we had a good discussion evaluating the most efficent ways to do this...and thanks for suggesting that LoTekK... constructive suggestions like that are more than welcome... always trying to find the best way :)
Torque Owner James Killick
-James