Gamestudio Links
Zorro Links
Newest Posts
WFO Training with parallel cores Zorro64
by Martin_HH. 02/24/26 19:51
Zorro version 3.0 prerelease!
by TipmyPip. 02/24/26 17:09
ZorroGPT
by TipmyPip. 02/23/26 21:52
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
5 registered members (Martin_HH, TipmyPip, AndrewAMD, Grant, USER0328), 5,287 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
alx, ApprenticeInMuc, PatrickH90, USER0328, Sfrdragon
19199 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
entity creat at mouse click #177255
01/10/08 04:14
01/10/08 04:14
Joined: Oct 2007
Posts: 85
H
harry3174 Offline OP
Junior Member
harry3174  Offline OP
Junior Member
H

Joined: Oct 2007
Posts: 85
Hi,

I try that when I click (left mouse button) ,at that position a earth entity
Will be create. I make function for this and call it in main ().But it can’t work.
Why?Please help.
Here is my code.

ENTITY* earth;
var a;
var b;
var c;
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);
}

}
function creat()
{
if (event_type == EVENT_CLICK)
{
while (mouse_left)
{
a = mouse_pos.x; // follow mouse x-pos
b = mouse_pos.y; // follow mouse y-pos
c = camera.z; // same as camera z-pos
earth = ent_create("earth.mdl",vector(a,b,camera.z), NULL);
wait(1);
}
}

}

Re: entity creat at mouse click [Re: harry3174] #177256
01/10/08 05:35
01/10/08 05:35
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
First of all, event triggers such as EVENT_CLICK are used for clicking on entities and stuff, not for mouseclicking in general. So upon calling the function creat(), the engine will never read the part within the if statement.

Second, you want to create an entity when you click the mouse, but your while statement will never be executed when you don't click the mouse first, and thus never wait for your input.

Third, when you create a view model, you should use ent_createlayer (I assume you want a view entity instead of a world entity as you define an entity as ENTITY*). Plus you place your model directly on the camera.z axis, you wont see it as your camera is now in the model.


So, time for the solution:
Code:

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

creat();

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

function creat()
{
while (1) //we will always check for user input, every frame
{
if (mouse_left) //left mouse has clicked!
{
you = ent_create("earth.mdl", 0, 10); //create earth.mdl view entity, no flags, on layer 10
you.x = mouse_pos.x;
you.y = mouse_pos.y;
you.z = 40; //40 quants in front of the camera
}
wait(1);
}
}



If you wanted a world entity instead, you need some more code for letting it follow the mouse. I'll help you on it if this is the case.

Ciao


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

Joined: Oct 2007
Posts: 85
Thank you for your co-operation.

I get error when i click on screen at runtime.
That is : Crash in creat : you=ent_create(@4,0,10)
Why ?

When i change layer 10 to NULL(you = ent_create("earth.mdl",0, NULL);)
than error gone entity creat but not excecty match mouse position.
It is just overlaping in one layer horizontaly.
Sorry i cant understand your third point properly.

please help.
Thanks

Re: entity creat at mouse click [Re: harry3174] #177258
01/11/08 13:24
01/11/08 13:24
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Well I made a little mistake. I wrote ent_create in my code instead of ent_createlayer. Ent_create makes an entity in the world, where the player walks too. Ent_createlayer makes an entity on the camera view. Thus independent of where the player walks and rotates, it's position will always be in the screen.

Seen that you did not know what I was talking about, I think you want the first option . My apologies, for I have not tested the code. I just blindly trust on my superb programming skills . So here an improved code:

Code:

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

creat();

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



function mouseTo3D() {
while (1) {
if (mouse_left) {
vec_set (mouse_click, mouse_dir3d); //get direction vector from mouse to world
vec_normalize(mouse_click, 4000); //give it a large distance for tracing
vec_add (mouse_click, camera.x); //calculate from camera position

c_trace (camera.x, mouse_click, IGNORE_MODELS); //trace from camera to clicked position (= mouse position + 4000 in depth)

return(target.x); //we return the new 3d vector for further use
}
wait(1)
}
}



function follow_mouse() {
while (me) {
vec_set(you.x, mouseTo3D());
wait(1);
}
}



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



Last edited by Joozey; 01/11/08 13:26.

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

Joined: Oct 2007
Posts: 85
Thanx for your kind co-opration.

I have error :
mouse_click--unknown parameter.
can i change mouse_click to temp ?

vec_set(you.x, mouseTo3D());--syntex error-vector expected.

Re: entity creat at mouse click [Re: harry3174] #177260
01/12/08 17:00
01/12/08 17:00
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
My mistake (again), replace the mouseTo3D() with the following code:
Code:

var mouse_click[3];

function mouseTo3D() {
vec_set (mouse_click, mouse_dir3d); //get direction vector from mouse to world
vec_normalize(mouse_click, 4000); //give it a large distance for tracing
vec_add (mouse_click, camera.x); //calculate from camera position

c_trace (camera.x, mouse_click, IGNORE_MODELS); //trace from camera to clicked position (= mouse position + 4000 in depth)

return(target); //we return the new 3d vector for further use
}




And if you would click the left mouse now, alot of entities are created. To prevent that, replace and type:
Code:

if (mouse_left) //left mouse has clicked!
{
you = ent_create("earth.mdl", nullvector, follow_mouse); //create earth.mdl and let it follow the mouse
while (mouse_left) {wait(1);}
}



Last edited by Joozey; 01/12/08 17:05.

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

Joined: Oct 2007
Posts: 85
Thank you Sir.

still i have one error.
vec_set(earth.x, mouseTo3D());-syntex error-vector expected.
we return the new 3d vector from function mouseTo3D() then
why we use function in vec_set instead of return value ?

please help

Re: entity creat at mouse click [Re: harry3174] #177262
01/16/08 14:50
01/16/08 14:50
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Myabe it's return(target.x); instead of return(target);

We need to copy the returned vector to earth.x, that is what vec_set does. You cant just copy a vector to anyother by using earth.x=mouseTo3D(), because that's for single values, not for arrays (which is what a vector is, var vector[3]).


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

Joined: Oct 2007
Posts: 85
Thank you Sir,

I can not copy that value in mousefollow function.
Here my try:
function follow_mouse()
{
vect=mouseTo3D();
while (me)
{
vec_set(earth.x,vect);
wait(1);
}
}
It gives me empty pointer error.
What should i do ?
Please help

Re: entity creat at mouse click [Re: harry3174] #177264
01/17/08 12:51
01/17/08 12:51
Joined: Oct 2004
Posts: 4,134
Netherlands
Joozey Offline
Expert
Joozey  Offline
Expert

Joined: Oct 2004
Posts: 4,134
Netherlands
Can you post all your code and variable declarations relevant to this function? How did you declare 'vect'?


Click and join the 3dgs irc community!
Room: #3dgs
Page 1 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