Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (SBGuy, dr_panther, Ayumi, Quad, AndrewAMD), 920 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 3 1 2 3
C-trace, click to place an object #279541
07/18/09 03:17
07/18/09 03:17
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

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.

Code:
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 Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Im not crash-hot with c-script, but here goes...
Code:
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 Offline
Serious User
Happy Birthday Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
I'd do it like this smile

Code:
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: EvilSOB] #279627
07/18/09 14:06
07/18/09 14:06
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
wow cool! That works, but i cant place an object while my camera is on an angle?

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 Offline
Expert
EvilSOB  Offline
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: EvilSOB] #279635
07/18/09 14:41
07/18/09 14:41
Joined: May 2004
Posts: 1,510
Denmark
Claus_N Offline
Serious User
Happy Birthday Claus_N  Offline
Serious User

Joined: May 2004
Posts: 1,510
Denmark
Mine should as well :p

Maybe you just forgot to replace "camera" with "view_build" in EvilSOB's code, if that is the view you're using. Other than that, both code examples should probably do it, though I'm not familiar with vec_rotate smile

Re: C-trace, click to place an object [Re: Claus_N] #279640
07/18/09 14:48
07/18/09 14:48
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Thank you guys sooo much everything works now! I really appreciate it!

Re: C-trace, click to place an object [Re: binsky33333] #282954
08/04/09 20:10
08/04/09 20:10
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Is there anyway where like i can make it so it displays the model and you can move your mouse around and the model will move with it. Kind of like a ghost so the player can see where they're putting the object. Then when you click it places the object?

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 Offline
Serious User
Happy Birthday Claus_N  Offline
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):

Code:
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
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Here is what i have. This is WDL script.
Code:
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.

Page 1 of 3 1 2 3

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