Alice Community Need help with camera.
 User Name Remember Me? Password

 Thread Tools Display Modes
 Need help with camera.
 byu rocks23 Junior Member   Status: Offline Posts: 3 Join Date: Aug 2012 Need help with camera. - 11-20-2012, 09: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.
 Dameria Senior Member     Status: Offline Posts: 976 Join Date: Sep 2009 Location: United States 11-21-2012, 11: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
 byu rocks23 Junior Member   Status: Offline Posts: 3 Join Date: Aug 2012 11-22-2012, 10:19 PM Is there a way to make it so it works on all screen sizes?
Dameria
Senior Member

Status: Offline
Posts: 976
Join Date: Sep 2009
Location: United States
11-23-2012, 11:29 AM

Quote:
 Originally Posted by byu rocks23 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
 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

 byu rocks23 Junior Member   Status: Offline Posts: 3 Join Date: Aug 2012 11-23-2012, 02: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 Senior Member     Status: Offline Posts: 976 Join Date: Sep 2009 Location: United States 11-24-2012, 11: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

 Thread Tools Display Modes Hybrid Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements     Community News and Announcements Alice 3     How Do I?     Works In Progress     Share Your World     Share Custom Classes     Bugs and Trouble Shooting     Suggestion Box Alice 2     How do I...?     Works-In-Progress     Share Worlds     Share Objects     Bugs and Troubleshooting     Suggestion Box Educators     Teaching with Alice     Teaching Using Alice 3     Teaching Using Alice 2     CS Principles and Alice     AP CSA and Intro to Java and Alice     Workshops General Discussion     Questions and Comments     The Lounge

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

 Contact Us - Alice.org - Archive - Top