Gamestudio Links
Zorro Links
Newest Posts
ZorroGPT
by TipmyPip. 02/26/26 11:53
Zorro version 3.0 prerelease!
by TipmyPip. 02/25/26 16:38
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Camera always moves upwards?
by clonman. 02/21/26 09:29
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 02/19/26 13:22
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
2 registered members (TipmyPip, the1), 5,583 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
the1, alx, ApprenticeInMuc, PatrickH90, USER0328
19200 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: entity creat at mouse click [Re: Joozey] #177265
01/18/08 04:22
01/18/08 04:22
Joined: Oct 2007
Posts: 85
H
harry3174 Offline OP
Junior Member
harry3174  Offline OP
Junior Member
H

Joined: Oct 2007
Posts: 85
Here is full code :
#include <default.c>
////////////////////////////////////////////

ENTITY* earth;
var vect[3];

function main()
{
level_load("ent_.wmb");
wait(2);
mouse_mode = 2;
creat();
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}

}
var mouse_click[3];
function mouseTo3D()
{

if (mouse_left)
{
vec_set (mouse_click, mouse_dir3d);
vec_normalize(mouse_click, 4000);
vec_add (mouse_click, camera.x);
c_trace (camera.x, mouse_click, IGNORE_MODELS);
return(target.x); //we return the new 3d vector for further use
}
}
}

function follow_mouse()
{
vect=mouseTo3D();
while (me)
{
//while (earth == NULL) { wait(1); }
vec_set(earth.x,vect);
wait(1);
}
}



function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse has clicked!
{
nyou = ent_create("earth.mdl", nullvector, follow_mouse);
while (mouse_left) {wait(1);}
}
wait(1);
}
}

I declare var vect[3];
Thank you very much.

Re: entity creat at mouse click [Re: harry3174] #177266
01/18/08 18:58
01/18/08 18:58
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Ah I was confusing Lite-C with c-script a little, this will work, I tested it :

Code:

#include <default.c>
////////////////////////////////////////////

var mouse_click[3];
function mouseTo3D(&vect)
{
vec_set (mouse_click, mouse_dir3d);
vec_normalize(mouse_click, 4000);
vec_add (mouse_click, camera.x);
c_trace (camera.x, mouse_click, IGNORE_MODELS);
vec_set (vect.x, target.x);
}


function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse was clicked!
{
you = ent_create("earth.mdl", nullvector, null);
mouseTo3D(you.x);
while (mouse_left) {wait(1);}
}
wait(1);
}
}

function mouse() {
mouse_mode = 2;
while(1)
{
mouse_pos.x = mouse_cursor.x;
mouse_pos.y = mouse_cursor.y;
wait (1);
}
}

function main()
{
level_load("Ent_.wmb");
wait(2);

mouse();
creat();
}




Last edited by Joozey; 01/18/08 18:58.

Click and join the 3dgs irc community!
Room: #3dgs
Re: entity creat at mouse click [Re: Joozey] #177267
01/19/08 12:53
01/19/08 12:53
Joined: Oct 2007
Posts: 85
H
harry3174 Offline OP
Junior Member
harry3174  Offline OP
Junior Member
H

Joined: Oct 2007
Posts: 85
Hi,

Thank you very very much.

Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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