Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Rotate object to mouse x,y

Author
Message
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 31st Jan 2004 20:52
I've got a turret model which is glued to the limb of a tank model. The unit crawls around the land and looks pretty good. But a major gameplay issue I'm trying to overcome involves the turret pointing the mouse cursor. I know how to rotate the turret left or right with the mouse, but couldn't figure out how to point it at the mouse.

I tried creating a 3d sphere which moves with the mouse, and then used ATANFULL() and WRAPVALUE() to calculate between the "fake" cursor and the turret. This worked initially, but only at the where the tank is placed on the terrain. The farther I move away from the start position, the less and less accurately the turret points. By the time I'm half-way across the map, the turret points in the opposite direction.

I'm sure there's a way to do this.

Thanks (I posted this in 3d, but with no replies)

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

TKF15H
21
Years of Service
User Offline
Joined: 20th Jul 2003
Location: Rio de Janeiro
Posted: 1st Feb 2004 02:23
you could post some code for us to look at...
I've done something similar, and I didn't use ATANFULL(),
so seeing your code will help.

Why do programmers always mix up Christmas and Halloween?
Because DEC 25 = OCT 31
Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 1st Feb 2004 03:15 Edited at: 1st Feb 2004 03:19
ur equasion is prolly right but u might have used the wrong variable or whatnot so if we get a look at it we might be able to help

hmm just as a side note ill post my code for the point to object that follows the mouse



it might seem excessive but it works.
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 1st Feb 2004 07:04
alright, here is my source. I've got the "tank" as a square which you control with the arrow keys and the "turret" as a smaller square glued to the bottom square. The sphere is the mouse "object". Now if you compile this, you should see that it works fine, until you start moving the tank.

This has been my problem the whole time. Right now I'm using "point object" but I was trying ATANFULL() before, but with the same results.

Thanks for the response.

Sorry about no comments on the code, just didn't have time.

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 1st Feb 2004 08:24
Hmm, well I tried your snippet Travis and it has the exact same problem as my code. The farther away from 0,0,0 the object moves, the less and less acurate it is.

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

Travis
21
Years of Service
User Offline
Joined: 9th Nov 2003
Location: West Aust.
Posted: 1st Feb 2004 08:57
hmm well i had a lok and noticed that the tank points towards the mouse asif the tank is still in the middel (when its not)... i dunno why, anyway i tryd using my code but because my game that thats from is orientated differently to urs i cant get it to work 100% properly but if i move t to the top corner i can see that it fixed ur problem...but it just makes others
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 1st Feb 2004 23:48
hmm, I know this is possible... and you'd think it'd be fairly simple. I thought POINT OBJECT would work, and it does, unless I move the main object, that the pointer is mounted to. Anyone else? It is so important to the gameplay, and I've been trying for about a week now with no success.

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

Toby Quan
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: U S A
Posted: 2nd Feb 2004 01:28 Edited at: 2nd Feb 2004 01:29
Hello Aluminum Pork. I got it to work correctly!

Replace these 2 lines in the rotate_object routine:

point object 2, x,y,z
set object rotation xyz 2


with these 3 lines:

intX = object position X(3) - object position X(1)
intZ = object position Z(3) - object position Z(1)
yrotate object 2, wrapvalue(atanfull(intX, intZ))
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 2nd Feb 2004 01:44
yeah, that works alot better! But if you rotate the "tank" then the "turret" rotates too, then setting it off of the cursor. Would there be anyway to rotate the tank without rotating the turret, but still have the turret follow the tank?

I imagine to do this I would have a seperate set of variables for the tank and the turret.

Any thoughts?

If not, I'm sure I can figure it out from here... thanks alot!

p.s. holy crap, ur from the cities? I'm from duluth, lol, like 2 hours from you!

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

Toby Quan
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: U S A
Posted: 2nd Feb 2004 05:29 Edited at: 2nd Feb 2004 05:29
Well, here's a simple solution. Only have the turret move when they click, instead of whenever the mouse moves. I just added this MouseClick check, and it seemed to be a workable solution:



Wow - it's nice to talk with someone in my own Time Zone! I married a woman from Duluth and we live in the Cities.
AluminumPork
21
Years of Service
User Offline
Joined: 28th Oct 2003
Location: Duluth, MN, USA
Posted: 2nd Feb 2004 06:12
well, I suppose that would work, but in the actual game I think that would get rather annoying if in order to move the turret you had to hold down the mouse button... but maybe, if you use left mb to rotate, and right mb to fire, maybe then it would work.

I also experimented un-glueing the turret from the tank, so the turret "always" points towards the cursor. But the problem with that solution is the equation that tilts the tank to the landscape. Before, it was fairly simple, I only had to rotate one object to the terrain, and the turret would do the same (because they are glued). But now I have to worry about two completely seperate objects, and the directions they're facing and blah blah blah. hmmm, I'll try that clicking thing, and see how it feels.

Thanks for the input.

P4 2.4Ghz HT, 512MB RAM, ATI Radeon 9600 128MB, 19" Viewsonic, 80GB HD

Login to post a reply

Server time is: 2025-05-22 11:09:19
Your offset time is: 2025-05-22 11:09:19