Mouse look?

You must understand the Game Editor concepts, before post here.

Mouse look?

Postby lcl » Fri Mar 01, 2013 6:52 pm

Hello.

I would like to add mouse look to Sabre, but it seems to be impossible since one can't lock the cursor in the middle of the window with GE.
I am already nearly sure that it's impossible, but still wanted to ask if someone knows a way to implement it in GE.

Thanks.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Mouse look?

Postby tzoli » Fri Mar 01, 2013 7:26 pm

I'm wondering if the mouse is out of the view is it still recording the coordinates of it?(It worths a try)
If yes just check the coordinates with draw actor and if changed you can set the new position.
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Mouse look?

Postby skydereign » Fri Mar 01, 2013 7:36 pm

It doesn't, xmouse and ymouse cannot be negative. You are right in assuming it can't be done in the way you describe. You could do it where if the mouse is within a certain distance from the middle of the screen, it starts turning (similar to a keydown event). If the player wants to stop turning, they move it to the center. It isn't as nice, but it could still work.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Mouse look?

Postby lcl » Fri Mar 01, 2013 7:54 pm

skydereign wrote:It doesn't, xmouse and ymouse cannot be negative. You are right in assuming it can't be done in the way you describe. You could do it where if the mouse is within a certain distance from the middle of the screen, it starts turning (similar to a keydown event). If the player wants to stop turning, they move it to the center. It isn't as nice, but it could still work.

Thanks. I'll use the other method.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Mouse look?

Postby bamby1983 » Fri Mar 22, 2013 4:10 am

You can achieve this by using the following code in you view actor's "Draw" event (you'll need to adjust the values to match your game's requirements). The attached GED file contains a working example of this code and will allow you to side-scroll horizontally through a panorama.

Code: Select all
if (xmouse<250&&view.x>=-1150)
    view.x-=3; // The number 3 represents the scroll speed
else if (xmouse>1110&&view.x<=640)
    view.x+=3;


Moving your mouse cursor to the far left or right of the screen will cause the screen to scroll in that direction. Please note that it is the view actor (the screen) itself that is moving and not the background. Moving the cursor away from the border area will make the screen stop scrolling. When the screen reaches the edge of the image, it will stop scrolling automatically.

The xmouse values correspond to the region in which the cursor needs to be to activate scrolling in the necessary direction. In case of the above code, this region extends 250 pixels from the left and right edges of the screen. The values corresponding to view.x relate to the left and right stopping points after which the screen will not scroll any further. The screen only scrolls so long as the stopping point values in the if-statement are met (i.e., the stopping points have not been reached yet).

The number 3 in the code represents the scroll speed. Increase this value to scroll faster and decrease it to scroll slower.

You can also scroll vertically and horizontally at the same time using the same logic. Just add a SEPARATE if- else-if statement for the y co-ordinates. Don't append else-ifs to the existing statement, else you won't get simultaneous x and y scrolling.

The attached GED file contains a live working demo of how the above code works.
Attachments
Mouse Scroll.zip
(5.51 MiB) Downloaded 122 times
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: Mouse look?

Postby Hblade » Fri Mar 22, 2013 4:48 pm

I thought about this as well lcl, but then again classic raycast games didn't use mice either :) Doom for example
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Mouse look?

Postby tzoli » Fri Mar 22, 2013 5:24 pm

Not sure but last time I played I was able to set to mouse look.
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Mouse look?

Postby Hblade » Fri Mar 22, 2013 6:46 pm

I mean console doom xD
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Mouse look?

Postby lcl » Fri Mar 22, 2013 7:53 pm

@Bamby1983: That's not what I meant with mouse look. Your example is the same that skydereign suggested.
But thanks anyway.

@Hblade: I see. I would want to add it anyway, I think it's much more pleasant to be able to use the mouse for looking around and aiming
things than using keys. :D But I will of course add the option to set the mouse look (well, it won't be a real mouse look, but something similar) off, too.
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Mouse look?

Postby Hblade » Fri Mar 22, 2013 9:26 pm

Agreed. Maybe if you had the source code of game-editor you can compile your own version that allows mouse lock
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Mouse look?

Postby bamby1983 » Fri Mar 22, 2013 11:42 pm

lcl wrote:@Bamby1983: That's not what I meant with mouse look. Your example is the same that skydereign suggested.
But thanks anyway.


Ahh sorry, I misunderstood the requirement. I believe what you're looking for is the kind of mouse look you see in first-person shooter games. Yes, it is possible to achieve this using GE. The attached GED file contains a working demo I just whipped up.

Just copy-paste the following code in the respective places and change the names of the 2 actors involved in your code (Background and Crosshairs). You will need to select the option to "Hide" your mouse cursor in the game settings to remove it from your screen. The Crosshair you see is actually an actor that is programatically anchored to the center of your screen.

The following code will:
1) Enable you to use mouse look as is done in FPS games
2) Continue scrolling the screen when the mouse is at the periphery of the screen.
3) Anchor the crosshairs at the center of the screen
4) Prevent you from moving beyond the background image boundary. This code will dynamically calculate the required values and therefore does not need to be modified for a new background image or view size


Paste the following in the global code. It is to declare a couple of variables we will be using:
Code: Select all
int xmouse_prev=xmouse;
int ymouse_prev=ymouse;


Paste the following in the view actor's "Create" event.
Code: Select all
// Initializing mouse position in variables
xmouse_prev=xmouse;
ymouse_prev=ymouse;


And finally, paste the following code in the view actor's "Draw" event.
Code: Select all
if(xmouse!=xmouse_prev) { // If the horizontal mouse position has changed
    view.x+=(xmouse-xmouse_prev); // Moving the view along with the mouse
    Crosshairs.x+=(xmouse-xmouse_prev); // Moving the crosshairs along with the view
    xmouse_prev=xmouse; // Setting value of xmouse_prev to xmouse for the next frame
                        }
else if (xmouse<=20) { // If the mouse is at the extreme left of the screen
    view.x-=10; // Moving the view to the left
    Crosshairs.x-=10; // Moving the crosshairs to the left
                    }
else if (xmouse>=view.width-40) { // If the mouse is at the extreme left of the screen
    view.x+=10; // Moving the view to the left
    Crosshairs.x+=10; // Moving the crosshairs to the left
                                }

if (view.x<=Background.x-(Background.width/2)) {
    view.x=Background.x-(Background.width/2);
    Crosshairs.x=view.x+(view.width/2);
                                               }
else if (view.x+view.width>=Background.x+(Background.width/2)) {
    view.x=Background.x+(Background.width/2)-view.width;
    Crosshairs.x=view.x+(view.width/2);
                                                               }


if(ymouse!=ymouse_prev) { // If the horizontal mouse position has changed
    view.y+=(ymouse-ymouse_prev); // Moving the view along with the mouse
    Crosshairs.y+=(ymouse-ymouse_prev); // Moving the crosshairs along with the view
    ymouse_prev=ymouse; // Setting value of ymouse_prev to ymouse for the next frame
                        }
else if (ymouse<=20) { // If the mouse is at the extreme left of the screen
    view.y-=10; // Moving the view to the left
    Crosshairs.y-=10; // Moving the crosshairs to the left
                    }
else if (ymouse>=view.height-40) { // If the mouse is at the extreme left of the screen
    view.y+=10; // Moving the view to the left
    Crosshairs.y+=10; // Moving the crosshairs to the left
                                }

if (view.y<=Background.y-(Background.height/2)) {
    view.y=Background.y-(Background.height/2);
    Crosshairs.y=view.y+(view.height/2);
                                               }
else if (view.y+view.height>=Background.y+(Background.height/2)) {
    view.y=Background.y+(Background.height/2)-view.height;
    Crosshairs.y=view.y+(view.height/2);
                                                               }
Attachments
Mouse Look.zip
(790.94 KiB) Downloaded 120 times
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: Mouse look?

Postby lcl » Sat Mar 23, 2013 12:26 am

@Bamby1983:
Yeah, I know that one can do that to almost achieve the real mouse look effect.
It works until the cursor reaches a side of the window, where the normal rotating based on the cursors movements becomes impossible since it can't move anymore to that direction.
I knew about this method when I started the topic, I just wanted to be sure if there is some way to avoid the problem caused by the cursor reaching the side of the window.
But it seems there isn't. Thank you for offering your help anyway. I'm sure your examples will be of use for someone else. You could even make a topic for them. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Mouse look?

Postby bamby1983 » Sat Mar 23, 2013 12:32 am

Are your referring to the scroll motion stopping when the mouse reaches the edge of the screen? If so, my example already took that into account and mitigated that issue. You can continue scrolling indefinitely in all directions, including after your cursor hits the edge of the screen. In fact, I imposed a programmatic limitation on the how far the player can scroll just so that he or she doesn't scroll beyond the background image and into a blank screen.

For example, try scrolling all the way to the left. Then move your cursor all the way to the right edge of the screen and leave it there. You'll notice that the screen continues scrolling right even after you've stopped moving your mouse (assuming you left it at the right edge of your screen). This rightwards scroll will only end once the view reaches the right edge of the background image, at which point it will cease scrolling.

Or have I misunderstood the issue (in which case please could you help me understand it better)?

EDIT: By the way, I have now encapsulated the above code into a reusable function that accepts the names of the background and crosshairs actors as arguments. No code customization is required to make it work for another game. You can access the function code and instructions on how to use it here if you like.
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Re: Mouse look?

Postby lcl » Sat Mar 23, 2013 11:48 am

bamby1983 wrote:Are your referring to the scroll motion stopping when the mouse reaches the edge of the screen? If so, my example already took that into account and mitigated that issue. You can continue scrolling indefinitely in all directions, including after your cursor hits the edge of the screen. In fact, I imposed a programmatic limitation on the how far the player can scroll just so that he or she doesn't scroll beyond the background image and into a blank screen.

I see your example had taken it into account and it works greatly for what you are trying to make it to do.
I'm sorry but I realized haven't explained you why that kind of workout isn't good enough for me.
I am working on a raycasting engine for Game Editor (viewtopic.php?f=6&t=12644) and while your mouse look
code is good for 2D games, it doesn't work too well in 3D games where the player has to be able to make 360 degree turns and still continue turning to that direction.
You see that moving mouse to the edge of the screen would make the turning effect to start acting differently compared to how
it works when the mouse is in the center of the window. That would make it pretty annoying to play the game. :/

I really should have explained that to you earlier. Your examples are very good for 2D games in which turning around won't be possible.
+1 for your efforts, I'm sure that someone finds your examples useful! :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Mouse look?

Postby bamby1983 » Sat Mar 23, 2013 6:44 pm

Ahh, thanks! I understand now! I've modified the code so that the player can look around as he would in a 3D game (where moving to the far left of the image would not stop movement but would enable the player to continue looking along the right of the screen seamlessly as though he were rotating, not scrolling). I've attached a GED file as a sample to demonstrate this effect on a world map. You can look all over the map as if you were looking at it all around you from inside a sphere. You will need to create your background images and position actors at image borders properly for this to appear seamless. We're actually using 2D animation to create the effect of a 3D environment. The code is more complex but I've added comments to make things easier to understand.

The same function works for both 2D and 3D games and the developer can choose between the two by specifying which mode he wants while calling the function ("2D" or "3D").

We can achieve the 3D turn around by writing code to make the view actor jump to the other side of the screen when it reaches the limit on one side. The background image would need to be created in a manner in which it is almost identical on both ends of the spectrum (so a part of it would repeat on any one side). There are some more checks in place to avoid infinite jumping and uneven transition in the code. You don't need to make any modifications to the code unless your game resolution is more than 1360 X 768. Just add an extra 10 pixels to your image -top and left for example - so these checks work smoothly.

As for the speed of the mouse look near the edges - yes, I noticed that does look different. We can work around that by making the scroll speed at the edges equal to the last scroll speed before the mouse hit the edges. I know it's not perfect, but the only scenario in which the player would notice a difference is if decides to change his scroll speed AFTER he hits the edge. This is a GE limitation and I do not know how to resolve it programatically. However, the player won't notice any difference so long as he continues scrolling at the same speed that he was moving at right before he hit the edge of the screen.
Attachments
Mouse Look.zip
(824.86 KiB) Downloaded 110 times
bamby1983
 
Posts: 112
Joined: Tue Jul 31, 2012 11:36 pm
Score: 8 Give a positive score

Next

Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron