Game Development Community

Hide and go seek objects(solved)

by Robert "Robc" Charney · in Torque Game Builder · 08/16/2006 (1:34 pm) · 3 replies

I could use help with a bug that I'm struggling to squash.

I have generally used the methodology described in the complex mouse tutorial to handle object picking and placement. This entails having an invisible mouse object that follows the cursor around. Picking objects off the game world involves mounting the game world object to the mouse object and dismounting to release it.

At the start of my level I wanted to have an object preloaded onto the mouse object to enable me to start a game clock at the moment that the player drops this object into the game world. No problem, I just created the object and mounted it the same as if it had been picked out of the game world.

On implementation of this system I have encountered a strange phenomenon. The object that I mount to the mouse object at the start of the game does not render, it is invisible. Invisible that is until I do one of the following: Alt-Tab out of the game and alt-tab back in or switch the resolution into or out of full screen. Once I take one of these actions then my mounted object appears attached to the mouse nice as you please. Once the object has become visible then resolution changes and alt-tab do not return the object to an invisible state, the problem is fixed for the duration of play.

I have also discovered that pre-mounting an object is not necessary to cause my problem. If I just try to pick something off the play field at the start of play then it will disappear until I take one of the actions described above to make it reappear. So I must have brought this problem upon myself because it didn't work this way when I first implemented the complex mouse code. And unfortunately I did not have good version control at the time the phenomenon started so backing up is not option... my bad, I know. I'm better at keeping versions now but I'm also reaching a point where I really need to figure out what I tweaked to bring about this problem and undo it.

So... short of starting all over again and rebuilding my mouse functions from the ground up, has anyone experienced and solved a similar situation... and can you clue me in to things I might look at to resolve the problem? Many thanks if you've had a similar strange encounter.

#1
08/17/2006 (6:53 pm)
Thats really odd. I'm not familiar with that code, but for a much simpler solution to the drag-and-drop problem, you might consider trying this tutorial. It's just a little script and no mounting is neccesary.
#2
08/17/2006 (8:07 pm)
Thanks Tom!
I am going to make one more attempt at debugging this issue this weekend after which I will try that code you linked because it looks a lot simpler than what I am using now. In fact I think I will try it even if I succeed in figuring out what I did wrong because its just plain good for me to see different ways to skin this cat. I am still learning.

Just for everybody's reference the 'complex mouse' I am referring to is in this tutorial here...

tdn.garagegames.com/wiki/Torque_2D/Getting_Started/ObjectSelection2Tutorial

I will say that I really like the way the complex mouse code works, the look and feel of mounted objects is nice and smooth and plenty responsive (once I increased the object maximum velocity that is), but I have tweaked the script so much now that my code doesn't look much like the original... and that's undoubtedly how I've created such a strange problem for myself
#3
08/20/2006 (6:56 pm)
Solved. The title of the thread really did end up being the problem, my objects weren't invisible... they had just taken a long hike way outside of my worldlimits, they were playing hide-n-go-seek after all! I have a moral to the story also... don't get greedy for speed.

For historic purposes and to help anyone else with a similar problem if they use that particular mouse code... here's what I discovered. I wanted my mouse object to stay very tight to the cursor so I bumped up the max object speed and the default object speed, I liked it... so I did it again, and again, and again. I ended up with both a default and a max mouse speed above 5000... no problem everything worked great. A month or so later I came back and realized that I wanted that same mouse object to have world limits so that when an object was attached to it the object stayed in the field of play no matter what the player did with the mouse cursor... that too worked great for much of the time. What I believe happened and that I wasn't immediately aware of is that if I didn't create objects to be attached to the cursor immediately adjacent to the cursor then the objects mounted together with the mouse object would fly into high gear and shoot way outside of the worldlimits, once out there in never never land they could never get back without overshooting the worldlimit on each timestep. I'm not sure if they oscillated or not but something weird was happening, so thats what I think was happening. Anyway, I had discovered before that creating objects outside of their worldlimits results in very unpredicatable results... now I believe that with enough velocity they can perhaps achieve an escape velocity? Anyway, that's where I found them... usually +/- 5000 units outside of their individual worldlimits with huge velocities and no hope of ever landing back in the play field (sized around +/-500 units).

Bottom Line... I dropped my object velocity back down to 500... all works great now. Also, be careful with mouseObj::pos and mouseobj::object.getPosition()... they are two very different things! I discovered some ancillary problems while squashing this bug. Thanks again Tom for your suggestion, I still plan to try that code out also. Case closed.