Using the mouse to create an entity on the level

Posted By: crumply

Using the mouse to create an entity on the level - 08/21/08 12:59

I'm trying to make my script create an entity by tracing a ray from the mouse down to the first collidable object in the level.

From what I understand from vector maths, I trace from the camera position to (mouse_dir3d*distance + camera position). I've tried for about 2 hours now and I still can't get it to work and I've also tried searching the forums and it always gives me the same list of topics that are completely irrelevant!

I am fuming!

Please someone put me out of my misery and tell me how it's done.

Here's my code:

Code:
	if(mouse_left == 1) // left Mousebutton pressed?
 		{
 			mousetracertemp.x = vector(0,0,0);
 			vec_add(mousetracertemp,mouse_dir3d);
 			vec_scale(mousetracertemp,1000);
 			vec_add(mousetracertemp,vector(camera.x,camera.y,camera.z));
			printv("yep",c_trace(camera, mousetracertemp, USE_POLYGON | IGNORE_ME));
			ent_create("mcube.mdl",mousetracertemp,NULL);
			printv("x",mousetracertemp.x);
			printv("y",mousetracertemp.y);
			printv("z",mousetracertemp.z);
			while(mouse_left==1) wait(1);
 	}

Posted By: pegamode

Re: Using the mouse to create an entity on the level - 08/21/08 13:11

Hi crumply,

maybe you could use a trace from camera position to the mousepointer.

This is the code I use in my point&click adventure:

pos2.x = mouse_pos.x;
pos2.y = mouse_pos.y;
pos2.z = 10000;
vec_for_screen (pos2, camera);
trace_mode = IGNORE_PASSABLE + IGNORE_PASSENTS + IGNORE_FLAG2;
c_trace (camera.x, pos2, trace_mode);

Now you can use 'target' to place your new entity.

Regards,
Pegamode

Posted By: Joozey

Re: Using the mouse to create an entity on the level - 08/21/08 13:14

http://www.coniserver.net/ubb7/ubbthreads.php?ubb=showflat&Number=166956
Posted By: crumply

Re: Using the mouse to create an entity on the level - 08/21/08 13:43

Joozey that's a good point you make about assigning the mouse_cursor. Both you guys helped me get it working and I am so happy right now laugh

here's what I'm working on, a survival sim:



GStudio forum saves the day again! laugh
Posted By: Joozey

Re: Using the mouse to create an entity on the level - 08/21/08 13:52

Looks like a fun start grin
Posted By: crumply

Re: Using the mouse to create an entity on the level - 08/21/08 18:10

http://www.youtube.com/watch?v=xI-Cgo7Tlo4 is when I modeled a tree laugh
Posted By: Joozey

Re: Using the mouse to create an entity on the level - 08/21/08 22:50

Oh that's freaky hehe, looks like zombie trees. Definately original ^^ would be great if it somehow animated a little so it really looks like it grows. I'm looking forward to see the rest laugh.
Posted By: phmenard

Re: Using the mouse to create an entity on the level - 08/25/08 00:01

crumpy how did you create the map in the bottom left hand corner ... I've been looking for a working example.
© 2024 lite-C Forums