Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (OptimusPrime, AndrewAMD), 14,580 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[solved] mouse click movement (strategy game) problem #385039
10/11/11 23:34
10/11/11 23:34
Joined: Dec 2010
Posts: 66
München (Germany)
dice Offline OP
Junior Member
dice  Offline OP
Junior Member

Joined: Dec 2010
Posts: 66
München (Germany)
Hello everybody,

Ive been struggling with this problem the whole evening!

Hopefully someone knows better about vectors and the whole stuff around it!

I'm using the camera view, that is about 1000 quants above the "playing area" with a tilt of -60°.
Now I have a player down there, which I want to move with the help of mouse clicks on blocks (the ground).

I dont know how to manage it! I tried several things with c_trace, vec_for_screen, rel_for_screen,
mouse_pos3d, mouse_dir3d, etc... but nothing will work correctly!

My idea was the following:
youre sending an (invisible) entity directly from the camera view to the ground and
let it stop when arrived at the bottom! Then let the player move to this entity and delete the entity...

Is the idea behind it okay? How can I realize it?

Greetings,
Tino

Last edited by dice; 10/13/11 13:52.
Re: mouse click movement (strategy game) problem [Re: dice] #385043
10/12/11 01:31
10/12/11 01:31
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
easiest way if you're just looking for an entity is mouse_ent.

if you need to do something using c_trace try
Code:
ENTITY* trace_getEntity(long flags){
	
	VECTOR vecFrom, vecTo;
	
	vec_set(vecFrom, vector(mouse_pos.x, mouse_pos.y, 0));
	vec_set(vecTo, vector(mouse_pos.x, mouse_pos.y, 5000));
	vec_for_screen(vecFrom, camera);
	vec_for_screen(vecTo, camera);
	
	var trace = c_trace(vecFrom, vecTo, flags);
	
	if(trace){
		return(hit.entity);
	}else{
		return(NULL);
	}
}

the code is pretty obvious as to what it's doing, just call this function on your event to direct the player

hope this helps

Re: mouse click movement (strategy game) problem [Re: MrGuest] #385054
10/12/11 08:08
10/12/11 08:08
Joined: Mar 2006
Posts: 1,993
Karlsruhe
PadMalcom Offline
Serious User
PadMalcom  Offline
Serious User

Joined: Mar 2006
Posts: 1,993
Karlsruhe
Hey dice, this idea can be realised much easier, you do not need to create an entity and let the player walk there! Just use MrGuests method to trace from your mouse position to the ground and when you hit your terrain/block you have the vector your player will have to walk to.

@MrGuest don't you need to do a vec_to_screen on the mouse position at the beginning? And you have to trace down to -5000 not to 5000 otherwise you'll trace up into the sky.

Re: mouse click movement (strategy game) problem [Re: PadMalcom] #385071
10/12/11 11:19
10/12/11 11:19
Joined: Dec 2003
Posts: 988
Germany, Magdeburg
JoGa Offline
User
JoGa  Offline
User

Joined: Dec 2003
Posts: 988
Germany, Magdeburg
I did this for my game on this way:

Code:
while(1)
{
	VECTOR to;
	if(mouse_right)		// Recktsklick ist Bewegung und Angreifen
	{
		//while(mouse_right)	{wait(1);}
		vec_set(to, mouse_dir3d);
		vec_normalize(to, 3000);
		vec_add(to, mouse_pos3d);
		c_trace(camera.x,to.x,IGNORE_ME|SCAN_TEXTURE);
		vec_set(maus_ziel.x,hit.x);
	}
	//[...]
	wait(1);
}


the vector maus_ziel is now the aim. If the distance from player and this vector (vec_dist) is more than 50 Quants, I turned the player to this position and moved him forwart, till the distance is < 50 Quants or he was stucked.

Re: mouse click movement (strategy game) problem [Re: JoGa] #385072
10/12/11 11:48
10/12/11 11:48
Joined: Dec 2010
Posts: 66
München (Germany)
dice Offline OP
Junior Member
dice  Offline OP
Junior Member

Joined: Dec 2010
Posts: 66
München (Germany)
Alright, the code of JoGa is working fine - thx a lot! I'll use this in my game...

Why is the first reply not working? I changed trace vector z to -5000, but it wont work frown

GreetZ,
dice

Last edited by dice; 10/12/11 11:49.
Re: mouse click movement (strategy game) problem [Re: PadMalcom] #385073
10/12/11 11:54
10/12/11 11:54
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
Originally Posted By: PadMalcom
Hey dice, this idea can be realised much easier, you do not need to create an entity and let the player walk there! Just use MrGuests method to trace from your mouse position to the ground and when you hit your terrain/block you have the vector your player will have to walk to.

@MrGuest don't you need to do a vec_to_screen on the mouse position at the beginning? And you have to trace down to -5000 not to 5000 otherwise you'll trace up into the sky.
here's it working
Code:
//trace

#include <acknex.h>
#include <default.c>

var TRACE_METHOD = 1; //change to 0 for mouse_ent method

ENTITY* trace_getEntity(long flags){
	
	VECTOR vecFrom, vecTo;
	
	vec_set(vecFrom, vector(mouse_pos.x, mouse_pos.y, 0));
	vec_set(vecTo, vector(mouse_pos.x, mouse_pos.y, 5000));
	vec_for_screen(vecFrom, camera);
	vec_for_screen(vecTo, camera);
	
	var trace = c_trace(vecFrom, vecTo, flags);
	
	if(trace){
		return(hit.entity);
	}else{
		return(NULL);
	}
}

void main(){
	
	mouse_mode = 4;
	level_load(NULL);
	
	int x, y;
	
	for(x = -128; x <= 128; x+=16){
		for(y = -128; y <= 128; y+=16){
			
			ent_create(CUBE_MDL, vector(x, y, 0), NULL);
		}
	}
	
	vec_set(camera.x, vector(-200, -200, 200));
	vec_set(camera.pan, vector(45, -45, 0));
	def_camera = 1;
	def_move();
	
	while(1){
		
		if(TRACE_METHOD == 0){
			if(mouse_ent){
				watched = mouse_ent;
				set(mouse_ent, LIGHT);
			}
		
		}else{
			
			you = trace_getEntity(SCAN_TEXTURE | USE_POLYGON | USE_BOX);
			if(you){
				watched = you;
				set(your, LIGHT);
			}
		}
		wait(1);
	}
}

vec_to_screen would convert a XYZ position to screen co-ordinates which we already have, and although -5000 would seem to make sense (using the traditional method of c_trace) it would place it 5000 quants behind the camera as you're converting it laugh


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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