Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Need help with camera.
Old
byu rocks23
Junior Member
 
Status: Offline
Posts: 3
Join Date: Aug 2012
Default Need help with camera. - 11-20-2012, 08:59 PM

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.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 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.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
byu rocks23
Junior Member
 
Status: Offline
Posts: 3
Join Date: Aug 2012
Default 11-22-2012, 09:19 PM

Is there a way to make it so it works on all screen sizes?
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 11-23-2012, 10:29 AM

Quote:
Originally Posted by byu rocks23 View Post
Is there a way to make it so it works on all screen sizes?
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.
Attached Files
File Type: a2w mouseMovement.a2w (210.6 KB, 16 views)


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Old
byu rocks23
Junior Member
 
Status: Offline
Posts: 3
Join Date: Aug 2012
Default 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.
   
Reply With Quote
Old
Dameria
Senior Member
 
Dameria's Avatar
 
Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
Default 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.


Check out my best projects so far and please comment:

Tic-Tac-Toe 2.0 ................... http://www.alice.org/community/showthread.php?t=3548
Alice Paint ........................... http://www.alice.org/community/showthread.php?p=23408
Real-Time Clock .................. http://www.alice.org/community/showthread.php?p=12725
Maze Game ......................... http://www.alice.org/community/showthread.php?t=4301
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.