Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, alibaba, Quad), 761 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
turning an object towards the mouse pointer #183584
02/12/08 19:21
02/12/08 19:21
Joined: Feb 2008
Posts: 21
J
jonkuhl Offline OP
Newbie
jonkuhl  Offline OP
Newbie
J

Joined: Feb 2008
Posts: 21
Hello there. I'm an old user who recently got back to the program. Due to money issues, I'm still using A6.

Now the issue I have is I have a tank that moves with wsad and a turret that is suppose to move with the mouse. However, with the code I have the turret only rotates to the positive y axis and doesn't follow the mouse very closely.

Code:
 

function mouse_trace()
{
from.X = MOUSE_POS.X; //set from.x to mouse_pos.x
from.Y = MOUSE_POS.Y; //set from.y to mouse_pos.y
from.Z = 0; //set from.z to zero
vec_set(to,from); //copy from to to
vec_for_screen(from,camera); //convert from to 3d coords
to.Z = 3000; //set to.z to 3000
vec_for_screen(to,camera); //convert to to 3d coords
return(trace(from,to)); //return the distance between from and to
}

action tankTurret
{
turret = my;
while(!player){ wait(1);} //wait for the player entity to load before doing anything
while(player) //once the player exists
{
my.x = player.x; //follow player
my.y = player.y;
my.z = player.z;
target = mouse_trace();
vec_diff(target,target,my.x);
vec_to_angle(my.pan,target); //turn to mouse
if((my.tilt != 0) || (my.roll != 0)) { my.tilt = 0; my.roll = 0;} //stay aligned with horizontal plane
wait(1);
}
}




That is the current code. It follows the body of the tank (player) fine. And the line of code that keeps it from rotating on roll and tilt seems to have no effect on how it turns to the mouse (I commented it out to see if it was interfering, no change)

And just a side note, mouse_trace() isn't strictly mine, it came from the forums about a year ago. I've used it in other projects and I know it works.

So the two issues are that (1) it only rotates to point to the left (even when I drive and turn the model around (2) it doesn't follow the mouse closely.

Is trace() too slow for this sort of thing? Is there a better way to do this?

Re: turning an object towards the mouse pointer [Re: jonkuhl] #183585
02/12/08 20:07
02/12/08 20:07
Joined: Feb 2008
Posts: 21
J
jonkuhl Offline OP
Newbie
jonkuhl  Offline OP
Newbie
J

Joined: Feb 2008
Posts: 21
Ha ha I found the solution.

I looked more closely at mouse_trace() and found it returns a distance, not a vector so instead I used the to[3] vector to rotate the cannon and it works.

Code:

action tankTurret
{
turret = my;
while(!player){ wait(1);} //wait for the player entity to load before doing anything
while(player) //once the player exists
{
my.x = player.x; //follow player
my.y = player.y;
my.z = player.z;
mouse_trace();
vec_diff(to,to,my.x);
vec_to_angle(my.pan,to);
if((my.tilt != 0) || (my.roll != 0)) { my.tilt = 0; my.roll = 0;} //stay aligned with horizontal plane
wait(1);
}
}




no changes were made to mouse_trace();


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