Gamestudio Links
Zorro Links
Newest Posts
Newbie Questions
by fairtrader. 12/05/23 10:32
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
Combine USD & BTC Pairs In Asset Loop
by TipmyPip. 11/26/23 08:30
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (fairtrader, AndrewAMD, ozgur, TipmyPip, Quad, alibaba), 582 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Mouse Aiming on 1 Z Coordinate #365712
03/28/11 18:54
03/28/11 18:54
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

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):
Code:
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. tongue

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 Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
i wrote this code some time ago

Code:
#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: txesmi] #365809
03/29/11 14:01
03/29/11 14:01
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Whenever I run it I get a script crash. I've tried putting it in actors, the main function, and in it's own function, but none seem to work.

Code:
vec_set(mousetemp,mouse_dir3d);
vec_scale(mousetemp, -mouse_height/mousetemp.z);
vec_add(mousetemp,camera.x);
mousetemp.z = mouse_ground;


I've made mouse_height and mouse_ground variables by the way, but with #define the script still crashes (I'm using A8 Commercial, if that makes any difference). Any idea why? Thanks for your help. laugh

Re: Mouse Aiming on 1 Z Coordinate [Re: Valdsator] #366333
04/02/11 21:14
04/02/11 21:14
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Bump. Anyone? I need help. :<

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 Offline
Serious User
txesmi  Offline
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
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

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.
Code:
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 Offline
Serious User
txesmi  Offline
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.

Code:
vec_sub ( mousetemp, player.x );
vec_to_angle ( atemp, mousetemp );
player.pan = atemp.pan;



Salud!

Re: Mouse Aiming on 1 Z Coordinate [Re: txesmi] #366410
04/03/11 16:28
04/03/11 16:28
Joined: Mar 2009
Posts: 186
V
Valdsator Offline OP
Member
Valdsator  Offline OP
Member
V

Joined: Mar 2009
Posts: 186
Ok, awesome! It works. grin

One last question. mouse_height basically tells the mouse where the "origin" of the aiming is. How should I measure it? Through guess and check I think I got the origin of the player, but is there a way to make it perfect?

Thank you so much. laugh

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 Offline
Serious User
txesmi  Offline
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)

Code:
mouse_height = camera.z - player.z;



Salud!

Re: Mouse Aiming on 1 Z Coordinate [Re: Valdsator] #383352
09/19/11 14:23
09/19/11 14:23
Joined: Jul 2009
Posts: 85
A
Altarius Offline
Junior Member
Altarius  Offline
Junior Member
A

Joined: Jul 2009
Posts: 85
hi,

Why if i made "MC_FIXED_HEIGHT" a variable i get a crash?

like this ..

var 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;

thx.

Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1