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:
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); }