Alice Community (http://www.alice.org/community/index.php)
-   How do I...? (http://www.alice.org/community/forumdisplay.php?f=16)
-   -   Need help with camera. (http://www.alice.org/community/showthread.php?t=9666)

 byu rocks23 11-20-2012 08:59 PM

Need help with camera.

I'm making an fps where the camera turns with the mouse. I want to pretty much copy the function "let the mouse orient the camera" except that you don't have to click and it works vertically. So far i can get the camera to turn right by doing the function- turn at speed right speed=[mouse distance from left edge]. This works but I can't get the camera to turn left because there is no mouse distance from right edge. Same thing with no function mouse distance from bottom.

 Dameria 11-21-2012 10:20 AM

Hint: If you rotate the camera to the right at a negative number, it turns left.

Answer: Find the total pixel length of the active screen (it's the value found from using the function [mouse distance from left edge] at the furthest right of the screen) and subtract half of that number from the to [mouse distance from left edge] function. For example, if there are 200 pixels in the window screen, then 100 would be half of that. If you are 120 pixels to the right of the left edge of the screen, then your camera will be rotating (120-100), which is 20 (right). If your mouse is 60 pixels from the left of the screen, your camera will be rotating at speed (60-100), which is -40 (left). You can then do the same thing with up and down.

Now you have to figure out how you are going to do that in Alice (remember that the window can be different sizes, so a fixed number like 100 for the midpoint will not always work if you change the active screen dimensions). This is just the theoretical explanation. If you are stuck and still don't know how to make it in Alice, I'll tell you how or you can ask me to make an example program for you.

 byu rocks23 11-22-2012 09:19 PM

Is there a way to make it so it works on all screen sizes?

 Dameria 11-23-2012 10:29 AM

1 Attachment(s)
[QUOTE=byu rocks23;51644]Is there a way to make it so it works on all screen sizes?[/QUOTE]

Yes there is. What I do is that I create two world variables, one for x coordinate and y coordinate (something like xVal and yVal). Then I create any object, I prefer a sphere, and I turn it red (so it's easier to see) and put it in the bottom left of the screen so only half of the sphere can be seen. Then put a 3d text in the center of the screen telling the user to "Click the red sphere". Now make a world method called "getCoords" and inside of that, put ("xVal" set equal to "[mouse distance from the left edge] / 2"). Then put an event in the events board and put "When the mouse is clicked on (sphere), do (getCoord)". Now you have the correct half value x coordinate for any sized screen.

Below is an even more complicated version that I quickly made that gets both x and y values, and creates a simple mouse movement. Actually, I'm looking at my code now, and the part where it gets the midpoint x value is redundant. You don't need to do the whole "click the sphere in the corner" part like I told you in the first part. Instead I used integers for the previous x and y values, and every time the mouse moves, it moves the camera and then sets a new previous x and y value to be used again. I also used a standard object (cube) to control the x coordinate movements, and set the camera vehicled to the cube. The y movement is turned by the camera. The reason the cube is there is to prevent the camera from going sideways when doing a combined right-left and up-down movement. If you don't understand it by looking at the method "mouseMovement", just ask me.

 byu rocks23 11-23-2012 01:04 PM

Thats great but one problem is that when the mouse goes all the way to the left or right the camera can't turn that way anymore. For example if the mouse goes all the way left it can turn left anymore.

 Dameria 11-24-2012 10:00 AM

A way you could fix that is if you put in code to automatically turn at a certain speed when it reaches the sides of the screen.

 All times are GMT -5. The time now is 07:09 AM.