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.

Newcomers DBPro Corner / Aligning mouse x/y 0,0; with player position x/y?

Author
Message
Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 16th Sep 2012 21:11
I'm having trouble working out the best way to align the cords 0,0,0 for the mouse's x,y,z with the x and y of the player.

I have designed a separate program that allows my player to shoot in a 180 arc, using the mouse; but i require mouse 0,0,0 to be the same as the player object's x,y,z.

The game is using 3d objects, but only using X and Y, so it works on a 2d plane; therefore i only need to know the X and Y cords of the mouse.

Any help would be much appreciated, i have tried a few equations but can't seem to get my head around it at the moment.

I you want i can supply the code
Thanks Sladey

Meep
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Sep 2012 09:58
There are many ways you can aproach this.
The least mathematical being to simply calculate the ratio of 3D space to pixels (because zdepth is same for all objects).
The easiest way would be to use DBPro's built-in function, PICK OBJECT() or PICK SCREEN() or something, to get the relative 2D coord of any 3D point.
Finally, you could take the very mathematical route and use some trig. If you know the xyz coords of an object, you can project a right-angle triangle to that point.
Personally, I'd go with option two. Just search the help index for the command. Not at my pc right now but if you haven't found it by then I'll post back.

Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 17th Sep 2012 14:23
thanks for reply, ill give the trig a go.

Meep
Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 17th Sep 2012 19:04
@non zero

Can't seem to find this command, had a look through the index but couldn't see anything.

Meep
Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 17th Sep 2012 19:21
Thought i might add, this code is what i want to use for my player.
As I said the prob is I can't get it to work without the x,y of the mouse relative to the player position.



Here is the game code sorry i'm new to programming and so its messy.

Didn't think i'd explained myself properly, probably still haven't



Meep
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 17th Sep 2012 21:04 Edited at: 17th Sep 2012 21:06
Ah, now I see what you're trying to do:

Have a look at this:


Is this what you are looking to do?

[EDIT] PS: Sorry it's a little weirdly formatted, I copy-pasted it from my RPLib library and my help doc. [/EDIT]

Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 17th Sep 2012 22:06
Hmm well it seems to nearly work, prob is the limb goes in the exact opposite direction, fiddled with a few variables but couldn't invert it.Not sure if that is a easy fix?

Not sure if this is due to the way the level is drawn in the 3d space, the bottom left corner of the level corresponds to 0,0,0 in 3d space. That was why I was finding it so hard to match the mouse x and mouse y to the 3d player object, as the mouse cords I assume are based on the screen resolution, not the 3d space in anyway.

Is there no way to tell the mouse that
player_object=mouse position 0,0,0
So any angles you calculate are based on the position of the player, which is moving thought the 3d space; and not a static place in the screen like the center?

Thanks for the example code, and all the help so far

Meep
nonZero
13
Years of Service
User Offline
Joined: 10th Jul 2011
Location: Dark Empire HQ, Otherworld, Silent Hill
Posted: 18th Sep 2012 13:48 Edited at: 18th Sep 2012 13:49
Quote: "prob is the limb goes in the exact opposite direction, fiddled with a few variables but couldn't invert it."

When working with limbs, it's about offsets AND angles.

Quote: "player_object=mouse position 0,0,0"

There's two ways. In this case we can use the crude way because z-depth isn't relevant

Hmmm, I'm not still not exactly sure exactly what you want so I made a crude example here:



If this is what you're trying to do and you need me to better explain it then I can do so.

Sladeh_boi
12
Years of Service
User Offline
Joined: 18th Jul 2012
Location:
Posted: 19th Sep 2012 12:58
Well I've figured it out finally

Well its more of a fix, I simply have the camera centered on the player at all times, and then used the first bit of code you posted, which gives the position in relation to the center. Your code allows the player to shoot below x=0 line whereas mine does not. I think it's to do with my use of tan which relies on working the angle from a triangle. In my code when the mouse goes into the negative Y cords, I think the sum of the triangle's angles exceed 180 and so it resets to 0.

Thanks for the posts, I appreciate the help, without them I think i would still be scratching my head. It's not exactly what I wanted, but its more than workable for my first game.

Meep

Login to post a reply

Server time is: 2024-11-21 23:31:38
Your offset time is: 2024-11-21 23:31:38