|
|
Mouse Aiming on 1 Z Coordinate
#365712
03/28/11 18:54
03/28/11 18:54
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
I've decided to try making mouse aiming for my game, and as I expected, ran in to some problems. Making something point to the mouse is really easy (surprisingly):
vec_to_angle(my.pan,mouse_dir3d);
Problem is, mouse_dir3d often goes through the ground in a level, resulting in your character looking in to the ground. Now, I've looked around the forums and have found a thread that has code which allows the mouse to look for terrain, and then sit on top of it. But, that makes my character jump around a bit when aiming at wall (even if roll and tilt are set to 0), because the mouse position is now on top of the wall. All I want is for the mouse z position to have 1 coordinate, so the character would always be aiming straight forward. Another problem is I don't really understand the code in that thread, and I don't want to use anything that I don't understand. I assume what I ask for is a tad (if not a lot) simpler. Hope what I said made some sense, and thanks in advance. 
|
|
|
Re: Mouse Aiming on 1 Z Coordinate
[Re: Valdsator]
#365785
03/29/11 10:35
03/29/11 10:35
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
i wrote this code some time ago
#define MC_FIXED_HEIGHT 200.0
#define MC_GROUND_HEIGHT 0
VECTOR vtemp;
...
vec_set ( vtemp, mouse_dir3d );
vec_scale ( vtemp, -MC_FIXED_HEIGHT / vtemp.z ); // & locked camera.tilt
vec_add ( vtemp, camera.x );
vtemp.z = MC_GROUND_HEIGHT;
hope it helps Salud!
|
|
|
Re: Mouse Aiming on 1 Z Coordinate
[Re: Valdsator]
#366379
04/03/11 10:47
04/03/11 10:47
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
the only thing i can imagine is that 'mousetemp.z' is equal to zero so the mouse is over the horizon. i have isolated that code into my learning project: http://www.box.net/shared/eggst12yxg. You can see it properly working with a -30 camera tilt. The code also does more things... Salud!
Last edited by txesmi; 04/03/11 11:00.
|
|
|
Re: Mouse Aiming on 1 Z Coordinate
[Re: txesmi]
#366393
04/03/11 13:47
04/03/11 13:47
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
Ok, after playing around with the z number, it seems that the mouse is now on the ground. But, the character still doesn't look at the mouse directly. I can aim with the mouse, but only in a certain angle range. I'm using this code to make the character aim at the mouse, by the way.
vec_to_angle(my.pan, mousetemp);
Could this be the problem? Thanks for your help so far txesmi, and thanks in advance to anyone else.
|
|
|
Re: Mouse Aiming on 1 Z Coordinate
[Re: Valdsator]
#366396
04/03/11 14:18
04/03/11 14:18
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
mousetemp allocates the mouse coordinates in a XY plane, so you need to calculate the vector from player to mousetemp and orientate the player as you did.
vec_sub ( mousetemp, player.x );
vec_to_angle ( atemp, mousetemp );
player.pan = atemp.pan;
Salud!
|
|
|
Re: Mouse Aiming on 1 Z Coordinate
[Re: Valdsator]
#366412
04/03/11 17:13
04/03/11 17:13
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
hi, more accurately, 'mouse_height' is the difference between camera.z and ground plane Z coordinate (player.z)
mouse_height = camera.z - player.z;
Salud!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|