| We hope you enjoy your visit. You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free. Join our community! If you are already a member please log in to your account to access all of our features: |
| Model Rotation Towards Mouse; How would I do it? | |
|---|---|
| Tweet Topic Started: Sep 24 2007, 08:47 AM (512 Views) | |
| jetjayjay | Sep 24 2007, 08:47 AM Post #1 |
|
Stupidity is a crime.
![]() ![]() ![]() ![]()
|
Well, as stated in the title, I need to know how I would rotate a model to face the mouse, in a third-person view, as shown below: |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''' :ph43r: ''''"""'''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| |'''''''''''''''''''''''''''''' '''''''''''''''''"""''''''||'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''| = Player:ph43r: = Mouse I need to do so in a way which will have the player's back facing the screen. The model should be able to rotate among both the X and the Y axis. For example: if the mouse is above the player (see diagram above) the model will be rotated upwards, and if the mouse is to the left of the player, the model will rotate to the left. Note: I do NOT mean this the way it is shown in Dr Best's collision example with the wolf. In this way, the mouse position is NOT set, and the model is rotated to face the mouse exactly. |
|
My dream is to become a cheesemonger. Yes, you heard me. A cheesemonger. What is a cheesemonger, you ask? Well, if a butcher cuts the meat, and the fishmonger cuts the fish, I think you can imagine what the cheesemonger does. | |
![]() |
|
| Haunebu | Sep 24 2007, 04:27 PM Post #2 |
![]()
WW2 games developer
![]() ![]() ![]() ![]() ![]()
|
I'd use rotx...rotz=camera.rotx...rotz and set camera position right behid the character. Or you can find the point of camera ray impact to the terrain or what and make the character look in that direction. |
![]() I don't like american heroes. | |
![]() |
|
| jetjayjay | Sep 24 2007, 05:35 PM Post #3 |
|
Stupidity is a crime.
![]() ![]() ![]() ![]()
|
I probably didn't explain very well - what I meant was, that unlike in, say, Dr Best's collision example, I don't want the mouse to control the direction of the camera. Like this: -----There is a robot. Let us call him Robot. (Creative, huh?) Robot is made of two parts: the head and the rest of the body. Now, Body moves around based on the arrow keys, turning left with Left, right with Right, and going forwards with Up. He can only turn on left and right, not up or down. The camera turn based on the direction he is moving in. -----Now for the Head. The mouse is not limited to one position, like in the collision example of Dr Best. It can move around within the limits of the screen, which are based on the direction of the body. In other words, it has no control over the direction Body is going in. Now, the Head model faces the direction of the Mouse, so that the model can be rotated among the X and Y axis to face the mouse. Hope you understood. I didn't. |
|
My dream is to become a cheesemonger. Yes, you heard me. A cheesemonger. What is a cheesemonger, you ask? Well, if a butcher cuts the meat, and the fishmonger cuts the fish, I think you can imagine what the cheesemonger does. | |
![]() |
|
| Ruud v A | Sep 25 2007, 07:56 AM Post #4 |
|
Programmer ˇ Artist
![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
I think he means something like pressing R twice in Blender. |
|
Veniogames Vēnit, ut mē occidĕret. I will not use Ultimate3d 2.x.x anymore - I am an Ogre C++ programmer. | |
![]() |
|
| MysteriXYZ | Sep 25 2007, 03:11 PM Post #5 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
So what you want, is to make the robot head look at a point in space, represented by the position of the mouse cursor, right? For the solution you need 2 things: first, you have to convert the screen coordinates of the mouse into 3D-coordinates, and second, you need to create a vector which points from the pivot of the robot head to that point in space. From that vector, you can derive the needed rotx and roty to rotate the head. So let's get to it. 1) The point being looked at in space For this, you use ScreenCoordToVector(...). This function returns a unit-length vector, pointing at whatever it is that the robot is looking at. But because its length is a bit short (exactly 1), the head would most likely be looking at a point behind the robot all the time. To remedy this, you need to scale the vector up with a value that gives the best results using CalculateVectorScalarProduct(...). This value depends on the distance of the robot from the camera, so you'll need to experiment. 2) The vector defining the direction of the robot head Now you can create the vector between the coordinates of the head and the coordinates of the point being looked at, using CreateVector(...). From this vector you can derive the rotation angles rotx and roty for the head, using my self-made GetOrientation(...) script:
And here is the main code, called in the Step Event of the Head object:
Simple, isn't it ;)? At least I hope it solves your problem :). |
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| jetjayjay | Sep 26 2007, 08:06 AM Post #6 |
|
Stupidity is a crime.
![]() ![]() ![]() ![]()
|
Wow... lol... you´re smart! I didn´t understand a thing, but it worked really well! Thank you MysteriXYZ!
|
|
My dream is to become a cheesemonger. Yes, you heard me. A cheesemonger. What is a cheesemonger, you ask? Well, if a butcher cuts the meat, and the fishmonger cuts the fish, I think you can imagine what the cheesemonger does. | |
![]() |
|
| « Previous Topic · Questions about Ultimate 3D · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)
'''''''''''''''''"""''''''|





2:34 AM Jul 11