|
C-trace, click to place an object
#279541
07/18/09 03:17
07/18/09 03:17
|
Joined: Dec 2008
Posts: 56
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
Hi everyone, i just have a quick question about using c_trace to place an object where i click. Ok basically i have a crosshair at the center of the screen. Basically what i need is when i click, a crate spawns on the ground, where the crosshair was pointed. Here is what i came up with so far.
temp.x = 399;
temp.y = 299;
temp.z = 100;
vec_for_screen(temp, view_build);
if(c_trace(temp, vector(0,0,-10000), NULL))
{
ent_create("crate.mdl", temp, NULL);
}
Its kinda working out. Though it will only go 100 quants for the temp.z If i make it any more it becomes very inaccurate. Can someone help me? BTW view_build is a camera. Thanks!
Last edited by binsky33333; 07/18/09 03:20.
|
|
|
Re: C-trace, click to place an object
[Re: binsky33333]
#279549
07/18/09 05:45
07/18/09 05:45
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Im not crash-hot with c-script, but here goes...
vec_set(temp, vector(1000,0,0)); //1000 is max "depth" to look
vec_rotate(temp, camera.pan);
if(c_trace(camera.x, vec_add(temp, camera.x), NULL))
{
ent_create("crate.mdl", target.x, NULL);
}
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: C-trace, click to place an object
[Re: EvilSOB]
#279626
07/18/09 14:02
07/18/09 14:02
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
Serious User
|
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
I'd do it like this
temp.x = crosshair_x;
temp.y = crosshair_y;
temp.z = 0;
vec_set(target,temp);
target.z = 10000;
vec_for_screen(temp,view_build);
vec_for_screen(target,view_build);
if(c_trace(temp,target,IGNORE_ME) > 0)
{
ent_create("crate.mdl",target,null);
}
|
|
|
Re: C-trace, click to place an object
[Re: binsky33333]
#279634
07/18/09 14:30
07/18/09 14:30
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Which one... Mine should.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: C-trace, click to place an object
[Re: binsky33333]
#283011
08/05/09 09:00
08/05/09 09:00
|
Joined: May 2004
Posts: 1,510 Denmark
Claus_N
Serious User
|
Serious User
Joined: May 2004
Posts: 1,510
Denmark
|
To move the object with the mouse, you just need to keep tracing (tracing like in the code sample in my post above). Here's an example (not tested):
ENTITY* ghostObject; // Global entity pointer
var isPlacingObject = 0; // Global variable
...
function PlaceObject(var _objectNum)
{
wait(1);
proc_kill(4);
isPlacingObject = _objectNum;
while(isPlacingObject != 0)
{
normal.x = crosshair_x;
normal.y = crosshair_y;
normal.z = 0;
vec_set(target,normal);
target.z = 10000;
vec_for_screen(normal,view_build);
vec_for_screen(target,view_build);
if(c_trace(normal,target,IGNORE_ME + IGNORE_PASSABLE) > 0)
{
if(mouse_left)
{
ent_create("crate.mdl",target,NULL);
if(ghostObject != NULL) {ptr_remove(ghostObject);}
isPlacingObject = 0;
break;
}
if(ghostObject == NULL)
{
ghostObject = ent_create("crate.mdl",target,NULL);
ghostObject.flags |= TRANSLUCENT;
ghostObject.flags |= PASSABLE;
ghostObject.alpha = 30;
}
else
{
vec_Set(ghostObject.x,target);
}
}
wait(1);
}
}
|
|
|
Re: C-trace, click to place an object
[Re: Claus_N]
#283101
08/05/09 17:43
08/05/09 17:43
|
Joined: Dec 2008
Posts: 56
binsky33333
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2008
Posts: 56
|
Here is what i have. This is WDL script.
entity ghostobject
{
flags = TRANSLUCENT;
alpha = 30;
}
var isplaceobject = 0;
function spawn()
{
while(isplaceobject == NULL)
{
temp.x = mouse_pos.x;
temp.y = mouse_pos.y;
temp.z = 0;
vec_set(target,temp);
target.z = 10000;
vec_for_screen(temp,view_build);
vec_for_screen(target,view_build);
if(c_trace(temp,target,IGNORE_ME | IGNORE_PASSABLE) > 0)
{
if(mouse_left)
{
ent_create("crate.mdl",target,null);
if(ghostobject == NULL)
{
ent_remove(ghostobject);
isplaceobject = 0;
}
}
if(ghostobject == NULL)
{
ghostobject = ent_create("crate.mdl",target,NULL);
}
else
{
vec_set(ghostobject.x,target);
}
wait(1);
}
}
}
Now the thing is when i click, it creates a huge line of boxes from the target to the camera. Also no ghost box appears, and when you click the engine just crashes from overwhelming boxes.
|
|
|
|