Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
4 registered members (AndrewAMD, fogman, Grant, juanex), 972 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Always Face Mouse #256488
03/17/09 01:58
03/17/09 01:58
Joined: Mar 2009
Posts: 3
USA
M
Memory Offline OP
Guest
Memory  Offline OP
Guest
M

Joined: Mar 2009
Posts: 3
USA
Hello all, I have joined the forum because I am having so much trouble I need help!

I am creating a game where I control the player's movement with W, A, S, and D and the player is always facing the mouse (which can freely move over the screen.) I need help getting the player to always face the mouse. I have searched the forums and online and found no clear way to do this that I understand.

In brief: I want an RTS unit to face the mouse wherever it is on screen. (Mouse position determines player's pan.) Latest syntax please.

-Memory

Re: Always Face Mouse [Re: Memory] #256492
03/17/09 03:40
03/17/09 03:40
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
this has been asked many times , have you tried doing a search in the forums for this?

Re: Always Face Mouse [Re: badapple] #256648
03/18/09 00:33
03/18/09 00:33
Joined: Mar 2009
Posts: 3
USA
M
Memory Offline OP
Guest
Memory  Offline OP
Guest
M

Joined: Mar 2009
Posts: 3
USA
I did search, and found a method, but my new code doesn't seem to work.

action player_controls()
{
player = my;
c_setminmax(my);
my.scale_x = 1.5;
my.scale_y = 1.5;
my.scale_z = 1.5;

var anim_percent;

VECTOR pointer_coords[3];
VECTOR ground_coords[3];
VECTOR pointer[3];
VECTOR return_value[3];
VECTOR new_temp[3];

camera.tilt = -45;
camera.pan = 90;

while(1)
{
camera.x = my.x;
camera.y = my.y - 800;
camera.z = my.z + 800;

mouse_pos.x = pointer.x;
mouse_pos.y = pointer.y;

pointer_coords.x = mouse_pos.x;
pointer_coords.y = mouse_pos.y;
pointer_coords.z = 0;

vec_for_screen(pointer_coords, camera);

ground_coords.x = mouse_pos.x;
ground_coords.y = mouse_pos.y;
ground_coords.z = 20000;

vec_for_screen(ground_coords, camera);

return_value = c_trace(pointer_coords, ground_coords, IGNORE_ME | IGNORE_PASSABLE);

vec_set (new_temp.x, return_value.x);
vec_sub (new_temp.x, player.x);
vec_to_angle (player.pan, new_temp);
player.tilt = 0;

if(key_w)
{
c_move(my, vector(10 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my, "run", anim_percent, ANM_CYCLE);
anim_percent += 10 * time_step;
}
if(key_s)
{
c_move(my, vector(-10 * time_step, 0, 0), nullvector, GLIDE);
ent_animate(my, "run", anim_percent, ANM_CYCLE);
anim_percent += 10 * time_step;
}
if(key_w != 1 && key_s != 1)
{
ent_animate(my, "stand", anim_percent, ANM_CYCLE);
anim_percent += 1 * time_step;
}
if(key_a)
{
my.pan += 10 * time_step;
}
if(key_d)
{
my.pan -= 10 * time_step;
}

c_move(my, vector(0, 0, -35 * time_step), nullvector, GLIDE);

wait(1);
}
}


Can anyone tell me why this doesn't work? It is based off of a post in the A7 forum. Any help would be appreciated.

Another thing: Is there any reason i can't get temp to work? I use a WDL file with my screen size information included, and a C file where all of my code is.

-M

Last edited by Memory; 03/18/09 00:34.
Re: Always Face Mouse [Re: Memory] #256652
03/18/09 01:49
03/18/09 01:49
Joined: Mar 2009
Posts: 3
USA
M
Memory Offline OP
Guest
Memory  Offline OP
Guest
M

Joined: Mar 2009
Posts: 3
USA
I solved it when I compared it to the RPG script from your site. I think the problem was c_trace returning a value that wasn't being stored in the variable I set it too.

Thanks,

-M

Re: Always Face Mouse [Re: Memory] #256656
03/18/09 03:19
03/18/09 03:19
Joined: Apr 2006
Posts: 624
DEEP 13
badapple Offline
User
badapple  Offline
User

Joined: Apr 2006
Posts: 624
DEEP 13
good job Memory smile


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