Mouse look in 3rd person view
by Sebastian Kiszkurno · in Technical Issues · 06/22/2007 (4:22 pm) · 1 replies
Hey guys, I'm new to TGE and this is my first post so take it easy on me.
What I'm trying to do is get the player to look towards the cursor while in 3rd person. After reading countless threads and resources, this is what I see as a good approach (excuse me if my terminology is off, I'm still trying to get the hang of it):
Based on the [url="http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2173"]Object selection in Torque[/url] resource, I figured getting a vector with endpoints at the camera world position and the 3d screen coordinates. Then shooting the ray into the world. At the x and y coordinates where it collides (I'm assuming you can set it to detect terrain collision) you set up a vector that goes straight up and down. This then will be the x,y coordinates to orient the character on the yaw axis. For pitch, there would be 2 cases. If a ray can go from the player's gun to the point on the ground, then the player will look just slightly above that point, so that the weapon will aim at torso level. If the ray from the gun to the point is blocked, the player's pitch will be adjusted to the smallest difference between target and actual. So basically if one player is on top of a building, the one on the ground will aim just above the edge of the roof (well both would aim just above that edge I guess).
So, is something like this feasable, and is it something someone new to TGE, no really coding can manage? Also, I suck at vector math so if there are resources on that I would appreciate it. Basically what I'm looking for is direction, not answers. If you can point me to where in the code to look and such, that would be a big help. Of course I dont want to reinvent the wheel, so if something like this exists, or parts of it, could you point me to them.
Lastly, if this doesn't exist, and I get something working, it will more than likely end up as a resource, unless I get it working and have no clue what I did, then a resource wouldn't be too helpful...
Anyway, thanks in advance for any help you can give.
What I'm trying to do is get the player to look towards the cursor while in 3rd person. After reading countless threads and resources, this is what I see as a good approach (excuse me if my terminology is off, I'm still trying to get the hang of it):
Based on the [url="http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2173"]Object selection in Torque[/url] resource, I figured getting a vector with endpoints at the camera world position and the 3d screen coordinates. Then shooting the ray into the world. At the x and y coordinates where it collides (I'm assuming you can set it to detect terrain collision) you set up a vector that goes straight up and down. This then will be the x,y coordinates to orient the character on the yaw axis. For pitch, there would be 2 cases. If a ray can go from the player's gun to the point on the ground, then the player will look just slightly above that point, so that the weapon will aim at torso level. If the ray from the gun to the point is blocked, the player's pitch will be adjusted to the smallest difference between target and actual. So basically if one player is on top of a building, the one on the ground will aim just above the edge of the roof (well both would aim just above that edge I guess).
So, is something like this feasable, and is it something someone new to TGE, no really coding can manage? Also, I suck at vector math so if there are resources on that I would appreciate it. Basically what I'm looking for is direction, not answers. If you can point me to where in the code to look and such, that would be a big help. Of course I dont want to reinvent the wheel, so if something like this exists, or parts of it, could you point me to them.
Lastly, if this doesn't exist, and I get something working, it will more than likely end up as a resource, unless I get it working and have no clue what I did, then a resource wouldn't be too helpful...
Anyway, thanks in advance for any help you can give.
Torque Owner Sebastian Kiszkurno