Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Ayumi), 662 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
mouse_pos3D #430595
09/29/13 14:29
09/29/13 14:29
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Hi, I am making a top down game with twin stick type controls. I am using the following lines to make the player character look at the mouse cursor:
Code:
while (my)
	{
	   vec_to_angle (my.pan,mouse_pos3d);
   	   my.tilt = 0;
        }


It works fine except for the fact that once I move from x=0, y=0 it doesn't work any more.
I think it's because the command I'm using checks the cursor's position in relation to the origin.
But I don't understand it in depth enough to know hwo to fix it.
Is there a way that I can either chose the reference point as something I can move dynamically.
Or is there another command or something that'll fit my needs better?
Thanks

Re: mouse_pos3D [Re: rtsgamer706] #430609
09/29/13 18:35
09/29/13 18:35
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Here's the entire loop, maybe my problem is with how I'm moving the camera or something

Code:
while (my)
	{
		vec_to_angle (my.pan,mouse_pos3d);
   	my.tilt = 0;
   //-----------Movement-----------
   	camera.x = my.x;
   	camera.y = my.y;
   	if (key_w)
	     c_move (me, nullvector, vector(20*time_step, 0, 0), IGNORE_PASSABLE); // move the player forward
	if (key_s)
	     c_move (me, nullvector, vector(-20*time_step, 0, 0), IGNORE_PASSABLE); // move the player forward
   	wait(1);
	}


Re: mouse_pos3D [Re: rtsgamer706] #430623
09/30/13 06:18
09/30/13 06:18
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You need to trace from mouse_pos3d to the ground using a scaled vector copy of mouse_dir(3d), then rotate the player to the trace target. Alternatively you can solve the equation of the line mouse_pos3d + mouse_dir*t so that the z-component of the result is the player height (which would be a better approach than using c_trace).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: mouse_pos3D [Re: Superku] #430667
09/30/13 17:28
09/30/13 17:28
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
I think I get the idea of what you're saying but I think I need to clarify something.
Even though I'm using the 3D engine the game is completely top down.
So there's no z component that I'm dealing with.
Is there a more direct way of fixing it since I'm not taking a Z component into account?

Re: mouse_pos3D [Re: rtsgamer706] #430697
09/30/13 23:24
09/30/13 23:24
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Sure there is a z-component involved. I assume you don't use an ISOMETRIC camera, correct? Then proceed as follows:

Your line is g(f) = mouse_pos3d + f*mouse_dir3d. You are looking for a specific f so that the z-component of g(f) is 0:

0 = mouse_pos3d.z + f*mouse_dir3d.z;
<=>
f = -mouse_pos3d.z/mouse_dir3d.z; // mouse_dir3d.z is != 0 because you are looking down

var f;
VECTOR dir;
vec_set(dir,mouse_dir3d);
vec_scale(dir,10); // depending on the camera height it can be beneficial to scale the dir vector for increased accuracy (because of the limited accuracy of var)
f = -mouse_pos3d.z/dir.z;
vec_scale(dir,f);
vec_add(dir,mouse_pos3d);

dir is now your target on the ground plane. Rotate your player to dir.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: mouse_pos3D [Re: Superku] #430703
10/01/13 00:07
10/01/13 00:07
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
hm, the line

f = -mouse_pos3d.z/dir.z;

seems to be giving me an error, it says "System Crash" whenever I run the program.
The fact that I'm dividing there seems to be the cause but I'm not sure why.

Re: mouse_pos3D [Re: rtsgamer706] #430707
10/01/13 00:53
10/01/13 00:53
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Your camera is looking downward (camera.tilt = -90 or 270) and you have your mouse activated in the engine?


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: mouse_pos3D [Re: Superku] #430709
10/01/13 00:58
10/01/13 00:58
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Camera.tilt = -90
and I have this in main:

while (1)
{
mouse_pos.x = mouse_cursor.x; // allow the mouse pointer to move
mouse_pos.y = mouse_cursor.y; // on the x and y axis
wait (1);
}

plus

mouse mode = 2;

am I forgetting something?

Last edited by rtsgamer706; 10/01/13 00:58.
Re: mouse_pos3D [Re: rtsgamer706] #430713
10/01/13 01:11
10/01/13 01:11
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Then debug the code (on your own), check critical values before calculation and the like.

Btw. this is how mouse_dir3d behaves:

Code:
void main()
{
	fps_max = 60;
	level_load(NULL);
	camera.z = 512;
	camera.tilt = -90;
	mouse_mode = 4;
	while(1)
	{
		DEBUG_VAR(mouse_dir3d.x,20);
		DEBUG_VAR(mouse_dir3d.y,40);
		DEBUG_VAR(mouse_dir3d.z,60);
		wait(1);
	}
}



You can try to add a "if(mouse_dir3d.z < 0) {...}" line around your mouse target calculation block.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

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