Game Development Community

Problems in setting Cursor like movement

by gigaslime · in Torque Game Builder · 07/31/2008 (1:24 am) · 6 replies

Hi, I am trying to make a game where this object will be placed where my cursor is even when the camera is moving, but its giving me some problems.

I tried the function onMouseMove() but the object wont follow the cursor when the camera moves and mouse doesn't.

Does anybody have a clue to solve this issue?

thank you

#1
07/31/2008 (8:36 am)
Even if the camera moves, the cursor is where you want to place the object right? So, shouldn't the cursor be the only thing you care about?

I guess the problem is there isn't a callback for that time when the camera has moved, so you don't have a good opertunity to know when you need to recalculate the world position for the object based on the camera and cursor position.

Maybe just recalculate it all the time? Use onUpdate or onFrame or whatever that callback that happens every frame is called...
#2
07/31/2008 (9:00 am)
OnUpdate is every 32ms (tick)

I think its something like onSceneUpdate for every frame, not got the docs on this laptop so don't quote me on that. OnUpdate will probably be enough though depending on what exactly you're trying to accomplish.
#3
07/31/2008 (3:39 pm)
Thank you James Ford and Craig Fortune.

I tried to use OnUpdate but I don't know how to get the cursor values. I created a global value in onMouseMove to save the value of the cursor and use it in OnUpdate but didn't work.

Is there any function or a way to get the cursor values?
#4
07/31/2008 (3:55 pm)
Well simply updating a global during an onMouseMove event is going to give you exactly the same issue as before.

Off the top of my head I'm recalling something simple like Canvas.getCursorPos(); Alas I think this'll give you the position of the cursor in pixels, so you'll need to check the resolution you're in etc and convert it all to world co-ords by offsetting it against the camera position... Hardly elegant however.
#5
07/31/2008 (4:43 pm)
It works!

Thank you Craig Fortune. I appreciate your help.
#6
07/31/2008 (4:56 pm)
Cool and no probs ;)