|
3 registered members (AndrewAMD, Grant, Neb),
908
guests, and 6
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
mouse_trace function
#244139
01/02/09 22:25
01/02/09 22:25
|
Joined: Dec 2008
Posts: 528 Wagga, Australia
the_mehmaster
OP
User
|
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
Ottawa
User
|
User
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 
|
|
|
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
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,209
İstanbul, Turkey
|
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
Member
|
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() 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 targetThis 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.
|
|
|
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
OP
User
|
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]
#244634
01/05/09 22:08
01/05/09 22:08
|
Joined: Oct 2008
Posts: 218 Nashua NH
heinekenbottle
Member
|
Member
Joined: Oct 2008
Posts: 218
Nashua NH
|
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.
|
|
|
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
OP
User
|
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!
|
|
|
|