Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, Quad, AndrewAMD), 936 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Mouse, aim #358625
02/12/11 14:30
02/12/11 14:30
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
I am a programmer working with the free version of lite-c, I am attempting to make a tanks game where the camera gives you a top down view and you aim and shoot with the mouse. Does anyone know how I can get the turret to rotate to my mouse?
Thanks for the help
Rtsgamer706

Re: Mouse, aim [Re: rtsgamer706] #358678
02/12/11 18:50
02/12/11 18:50
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
I've made progress!
I found something called mouse_dir3d.
So I added:

action b_gun()
{
set(my,PASSABLE);
while(my)
{
vec_for_vertex(me.x, basic, 365);
vec_to_angle(my.pan,mouse_dir3d);
wait(1);
}
}
this works pretty well as the cannon does aim towards my mouse.
The problem now is that the farther away my mouse is from the cannon the higher up it aims!
Does anyone know how to lock the tilt and roll of the cannon or some other way to fix that problem?
I already tried:

my.tilt = clamp(my.tilt,0,0);

and it doesn't work, =(
Thanks for the help
Rtsgamer706

Re: Mouse, aim [Re: rtsgamer706] #358690
02/12/11 20:51
02/12/11 20:51
Joined: Nov 2006
Posts: 497
Ohio
xbox Offline
Senior Member
xbox  Offline
Senior Member

Joined: Nov 2006
Posts: 497
Ohio
not saying it will work, but you can try,

my.tilt = clamp(0, my.tilt, 0);

I suggest this because from my thinking,
my.x = my. pan (x is the first element in the position vector, and pan is the first element in the Angle vector)
my.y = my. tilt (y is the second element in the position vector, and tilt is the second element in the angle vector)
my.z = my. roll

just a thought...

Re: Mouse, aim [Re: xbox] #358729
02/13/11 00:02
02/13/11 00:02
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
no luck,
Thanks for the reply though,
any other suggestions?

Re: Mouse, aim [Re: rtsgamer706] #358737
02/13/11 04:31
02/13/11 04:31
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
this wouldnt be hard . i work with the free lite c myself , and if you dont figure it out ill make something quick for ya

Re: Mouse, aim [Re: badapple] #358776
02/13/11 12:19
02/13/11 12:19
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
You seem to know what your doing,
so can you just tell me how to fix my problem please?

Re: Mouse, aim [Re: rtsgamer706] #358779
02/13/11 12:45
02/13/11 12:45
Joined: Feb 2010
Posts: 886
Random Offline
User
Random  Offline
User

Joined: Feb 2010
Posts: 886
Like this;

Click to reveal..
function mouse_aim()
{
proc_mode=PROC_LATE;
VECTOR weaponOffset;
while(1)
{
if(mouse_right == 1)// hold it to aim.
{
camera.arc = 50; // zoom alittlebit
//set position
////////////////////////////////
vec_set (weaponOffset.x, vector (?, ?, ?));
vec_rotate (weaponOffset.x, vector (camera.pan, camera.tilt, 0));
vec_add (weaponOffset.x, camera.x);
vec_set (my.x, weaponOffset.x);
my.pan = camera.pan;
my.tilt = camera.tilt;
wait(1);
//end of setting the position
////////////////////////////////
}
else //When your not pressing mouse right.
{
camera.arc = 80;
vec_set(my.x,weaponOffset);
vec_rotate(my.x,camera.pan);
vec_add(my.x,camera.x);
vec_set(my.pan,camera.pan);
my.pan = camera.pan;
my.tilt = camera.tilt;
wait(1);
}
}
}


It`s tested and it works.
You just must play with the numbers to set the right position.



Re: Mouse, aim [Re: Random] #358789
02/13/11 13:16
02/13/11 13:16
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
Your code probably does work but can you be more specific as of what I should do with it please?
When I added it to my original action or just told the gun to run it by itself, both times the gun just disappeared!
Do you want me to put it after my original action, in my original action, should it replace my original action completely?
thanks for the code, but how do I use it???
Rtsgamer706

Re: Mouse, aim [Re: rtsgamer706] #358793
02/13/11 13:32
02/13/11 13:32
Joined: Oct 2009
Posts: 149
Germany
M
muffel Offline
Member
muffel  Offline
Member
M

Joined: Oct 2009
Posts: 149
Germany
with this code you get the nearest position on the terrain under your cursor. this position is stored in the mouse3d_vec vector
Code:
vec_set(temp,mouse_dir3d);
vec_scale(temp,1000); // set a range
vec_add(temp,mouse_pos3d);
c_trace(mouse_pos3d,temp,IGNORE_MODELS|IGNORE_SPRITES);
vec_set( mouse3d_vec , target );



the code is tested
put it in the mainloop
declare temp as a local vector and mouse3d_vec as a global vector

muffel

Re: Mouse, aim [Re: muffel] #358795
02/13/11 13:37
02/13/11 13:37
Joined: Dec 2009
Posts: 361
R
rtsgamer706 Offline OP
Senior Member
rtsgamer706  Offline OP
Senior Member
R

Joined: Dec 2009
Posts: 361
VECTOR mouse3d_vec;

action b_gun()
{
// set(my,PASSABLE);
VECTOR temp;
while(my)
{
my.tilt = clamp(0, my.tilt, 0);
vec_for_vertex(me.x, basic, 365);
vec_to_angle(my.pan,mouse_dir3d);
vec_set(temp,mouse_dir3d);
vec_scale(temp,1000); // set a range
vec_add(temp,mouse_pos3d);
c_trace(mouse_pos3d,temp,IGNORE_MODELS|IGNORE_SPRITES);
vec_set( mouse3d_vec , target );
wait(1);
}
}

This is what that action currently looks like, it has not changed my problem,
(Turret still aims up and down) what did i do wrong?
thanks
rtsgamer706

Page 1 of 2 1 2

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