Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Akow, 1 invisible), 1,417 guests, and 12 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Entity to look at mouse #251476
02/13/09 09:29
02/13/09 09:29
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
Alright, I'm driving myself crazy. I've been bored lately and have started getting back into game design again just shits and giggles. It's been years since I've posted here I think, and I haven't used 3DGS in forever either. So needless to say, I think, I've forgotten very basic things.

I'm driving myself crazy with C_Rotate and Vec_to_angle.

Image this: I have a sprite the view is top down the sprite is my character. I want the sprite to angle itself so that it appears facing the mouse, which is a target shape. Obviously the mouse is the aimer.

I don't know what it is I cant get right but it just dosen't work. I'm lost.

Simplied, how do I make sprite seem to face the mouse's position.


-Johnny Thrash
Re: Entity to look at mouse [Re: Metal_Thrasher] #251619
02/14/09 06:22
02/14/09 06:22
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
Okay so the problem was using a sprite the way i was. So I used a model thatis a cube with the top side use the character graphic. Basicaly is simulates the same thing...
but i still have trouble...

Code:
  vec_to_angle(my.pan,mouse_pos);

That's all the code I used to acheive the effect. But something's deffinitely missing. It pans when I move the mouse...but it still doesn't look at where the mouse is. any suggestions???
Thanks in advance

Last edited by Metal_Thrasher; 02/14/09 06:22.

-Johnny Thrash
Re: Entity to look at mouse [Re: Metal_Thrasher] #252186
02/16/09 23:33
02/16/09 23:33
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
Is there a way to make a trace from the mouse to the ground? I ffigure that might do the trick. But i don't know. Sorry to conitnuely replying to myself, but I reeally need help on this.


-Johnny Thrash
Re: Entity to look at mouse [Re: Metal_Thrasher] #252196
02/17/09 00:30
02/17/09 00:30
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Replying to yourself might do the trick to get an advice, because you are explaining the problem more and more and show that you take efforts yourself! wink

vec_for_screen is your best choice. If the distance between camera and surface is always the same, a fixed value for z will do it.

If the distance varies, you have to add a trace between two vec_for_screen positions, means two different values of z, that means that you send a trace rectangular to the screens 'surface', to get the distance to the surface.

http://www.conitec.net/beta/avec_for_screen.htm

Re: Entity to look at mouse [Re: Pappenheimer] #252208
02/17/09 05:22
02/17/09 05:22
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
Thanks alot man! That did the trick. Vec_For_Screen! i forgotten all about that one, thank again!


-Johnny Thrash
Re: Entity to look at mouse [Re: Metal_Thrasher] #252212
02/17/09 06:18
02/17/09 06:18
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
Okay, it looked like it had worked, but not so. It works fine from the center of the playing feild, which is my starting point. But once I move the character to other places it gets buggy and get begin to look in the wrong direction and acts as though the mouse is right over top of him. Here my code for aiming
Code:
	while(1)
	{
		
  temp.x = mouse_pos.x;
  temp.y = mouse_pos.y;
  temp.z = -1000;
  vec_for_screen(temp,camera);
  


  vec_to_angle(my.pan,temp); // now MY looks at YOU
  my.tilt=0;
  my.roll=0;
  
  wait(1);
  
  camera.x=my.x;
  camera.y=my.y;
  

	
	
	}


You can Download my level so far HERE (3.19 MB) .

Try moving the character away from the center of the screen, you'll see the problem.
Controls are W,A,S,D and mouse to aim.

Last edited by Metal_Thrasher; 02/17/09 06:19.

-Johnny Thrash
Re: Entity to look at mouse [Re: Metal_Thrasher] #252798
02/20/09 09:07
02/20/09 09:07
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
before you use temp for the vec_to_angle function you need to set the position of temp in relation to the position of the player.
As long as the player is at position vector(0,0,0) it works, because such values don't change anything! wink

Use something like the following:
function turn_towards_target()
{
// get the direction from the entity MY to the entity YOU
vec_set(temp,your.x);
vec_sub(temp,my.x);
vec_to_angle(my.pan,temp); // now MY looks at YOU
}

You already got the first and the third line of this snippet, you still need the second line.

Look for others examples of vector calculation in c-script in the manual, in the AUM and Kinji's Vector tutorials, to get an idea how they work! smile

Re: Entity to look at mouse [Re: Pappenheimer] #252835
02/20/09 19:02
02/20/09 19:02
Joined: Oct 2003
Posts: 2,194
Saturn
Metal_Thrasher Offline OP
Expert
Metal_Thrasher  Offline OP
Expert

Joined: Oct 2003
Posts: 2,194
Saturn
lmao, damn that did the trick. Just the one line of code made the differance. Wow, it makes sense too. I don't know why I didn't think of that. Thanks a ton man. You saved my game. =D


-Johnny Thrash

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