Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
3 registered members (AndrewAMD, Grant, Neb), 908 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
mouse_trace function #244139
01/02/09 22:25
01/02/09 22:25
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
I was linked to the following function when I asked for code to send a trace from the mouse to below ground(for an rts).This code was going to be used for selection purposes etc. could someone fix this so it worked,or write a new one with the same purpose?
here is the function:
code\
VECTOR targVec;
function mouseTrace()
{
VECTOR from;
VECTOR to;
from = vec_for_vertex(mouse_pos,camera);
to.x = mouse_pos.x;
to.y = mouse_pos.y;
to.z = -3000;
c_trace(from,to,IGNORE_PASSABLE | IGNORE_SPRITES | IGNORE_MODELS);
vec_set(targVec,target);
}
\code

please help!
any help is greatly appreciated.
thanks in advance!

Last edited by the_mehmaster; 01/02/09 22:27.
Re: mouse_trace function [Re: the_mehmaster] #244163
01/03/09 00:17
01/03/09 00:17
Joined: Apr 2006
Posts: 737
Ottawa, Canada
O
Ottawa Offline
User
Ottawa  Offline
User
O

Joined: Apr 2006
Posts: 737
Ottawa, Canada
Hi!

Try changing this
VECTOR targVec;


to
VECTOR* targVec;

You can read on this topic in the following section of the manual
Mistake 4: Using pointers the wrong way
under Beginner's mistake....(it's the title of the section)

Ottawa smile

Re: mouse_trace function [Re: Ottawa] #244168
01/03/09 00:58
01/03/09 00:58
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
Quad Offline
Senior Expert
Quad  Offline
Senior Expert

Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
Code:
void amarker(){

	VECTOR* to = vector(0,0,0);
	VECTOR* from = vector(0,0,0);
	
	set(my,PASSABLE);
	while(1){
		from = vec_for_screen(mouse_cursor,camera);	
		from.z = camera.z;
		vec_set(to,from);
		to.z -=500;
		c_trace(from,to,IGNORE_ME|IGNORE_PASSABLE);
		vec_set(my.x,target);
		wait(1);
	}
}


Last edited by Quadraxas; 01/03/09 00:58.

3333333333
Re: mouse_trace function [Re: the_mehmaster] #244178
01/03/09 02:50
01/03/09 02:50
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Did I post this? I've used "mouseTrace()" a few times in my own scripts, almost exactly like that.

You have "vec_for_vertex" where it should be "vec_for_screen."

It might also be a pointer problem, "from," in my script, is a pointer. I did not set "to" as a pointer.

Also, be sure that mouse_mode is >= 1.

Just in case it helps, this is a modified script that uses the mouse_trace()

Code:
function mouseTrace()
{	
	VECTOR bmuzzle;
	var mgLoad = 0;
	while(player.health > 0)		//while the player is alive
	{
		VECTOR* from;										//declare a vector pointer for vec_for_screen
		VECTOR to;											//declare a vector for c_trace
		from = vec_for_screen(mouse_pos,camera);	//convert the mouse_position to 3D coords
		to.x = mouse_pos.x;							//set to to the mouse point and -3000
		to.y = mouse_pos.y;
		to.z = -3000;
		c_trace(from,to,IGNORE_MODELS);			//trace from from to to, ignorning models
		vec_sub(target,my.x);						//subtract vectors
		vec_to_angle(my.pan,target.x);			//turn to target


This code in particular traces from mouse to the ground to give a tank turret a vector to turn to. (Isometric tank game). Code works fine.

Last edited by heinekenbottle; 01/03/09 02:55.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: mouse_trace function [Re: heinekenbottle] #244348
01/04/09 06:33
01/04/09 06:33
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Yes, heinekenbottle, that is your code. i was linked to it when i asked for an rts selection system.

What exactly is it ment to do? i can see that you can use it for directional purposes, but how could i use it for an rts selection system? i have lasso figured out, I just need a way to send a ray from the mouse, to underground, with the camera at an angle. then i can c_trace between them and find the coordinates of the hit object. sort of like event_click,but i cannot find coordinates with that,can I?

please help!
btw, thanks for your answers guys!

Re: mouse_trace function [Re: the_mehmaster] #244632
01/05/09 21:48
01/05/09 21:48
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
Anyone?

Re: mouse_trace function [Re: the_mehmaster] #244634
01/05/09 22:08
01/05/09 22:08
Joined: Oct 2008
Posts: 218
Nashua NH
heinekenbottle Offline
Member
heinekenbottle  Offline
Member

Joined: Oct 2008
Posts: 218
Nashua NH
Originally Posted By: the_mehmaster
Yes, heinekenbottle, that is your code. i was linked to it when i asked for an rts selection system.

What exactly is it ment to do? i can see that you can use it for directional purposes, but how could i use it for an rts selection system? i have lasso figured out, I just need a way to send a ray from the mouse, to underground, with the camera at an angle. then i can c_trace between them and find the coordinates of the hit object. sort of like event_click,but i cannot find coordinates with that,can I?

please help!
btw, thanks for your answers guys!


For selection, I just use "event_click"

However, mouse_trace would come to play when I want to give movement orders.

Since the target of the trace is on the ground below the mouse, the target can be used to move a unit to that position.

EDIT: It probably wouldn't be that hard to adapt the snippet I posted to do such a thing. Simply copy the vector to the skills of your units and direct them to go to that vector and when they are within, say, 20 units from the vector, they stop (you won't be 100% accurate, 20 units should be close enough, any closer and the entity won't stop moving)

Last edited by heinekenbottle; 01/05/09 22:12.

I was once Anonymous_Alcoholic.

Code Breakpoint;
Re: mouse_trace function [Re: heinekenbottle] #244641
01/05/09 23:26
01/05/09 23:26
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
hey thanks for your help, but what i really needed was a sort of continuous event_click function, so i could use it for lassoing units. So i wrote my own function for selection(it sort of works backwards):
VECTOR* pos = vector(0,0,0);
function mouse_trace()
{
while(1)
{
if(mouse_left)
{
pos = vec_to_screen(vector(my.x,my.y,my.z),camera);
if(pos != NULL)
{
pos.z = 0;
if(vec_dist(pos,vector(mouse_pos.x,mouse_pos.y,0))<=30)my.ambient = 1000;
else my.ambient = 0;
}
}
wait(1);
}

}

with that function, if i click on something,it lights up. with the way it is written, i can also adapt it to lasso selection, as selection depends on mouse position, so i can compare it with an onscreen box.Also, the camera can be at any angle(important in my 3d rts)

now, with your function..
when I used your mouse_trace function, for debugging i drew a point3d at the target vector, but for some reason, the point3d only moved a tiny bit over the terrain when i moved the mouse! (note - camera.tilt was at -60 if you need this info)

I desperately need your function to make the unit move, as i have selection figured out now.

thanks in advance!

Re: mouse_trace function [Re: the_mehmaster] #271028
06/10/09 20:52
06/10/09 20:52
Joined: Dec 2008
Posts: 528
Wagga, Australia
the_mehmaster Offline OP
User
the_mehmaster  Offline OP
User

Joined: Dec 2008
Posts: 528
Wagga, Australia
problem solved. Thanks everyone!


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

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