playMaker

Author Topic: Mouse Lock - Resets mouse position to screen center?  (Read 13538 times)

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Mouse Lock - Resets mouse position to screen center?
« on: July 18, 2013, 03:47:15 PM »
Hi guys - simple question here!

When i lock my mouse cursor and then unlock it again, the mouse appears at the center of the screen =/ Is there any way to change it so it re-appears at the position it was at when it was locked to begin with? I know i can get the mouse X and Y position, but i can't seem to figure out how to set the position when it's unlocked again

any help is recieved with virtual hugs <3
Remember, you don't fail unless you give up trying to succeed!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #1 on: July 28, 2013, 12:37:01 PM »
Hi,

 not possible from what I can gather on the web. What's the problem you are having with this current behavior?

 if you are using absolute positioning to move elements on screen, then you'll to refactor to take in account relative movement of the mouse, to stop relying on the absolute position.

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #2 on: July 28, 2013, 04:41:37 PM »
Hi Jean! That's a shame =(

I am making a top-down shooter, where the character always looks at the mouse-pick position. By holding right click, the mouse will lock, and the player can rotate the camera. Upon releasing right click, it unlocks the mouse again which then appears in the center of the screen and makes the character rotate to look in a random direction. This fixes itself as the player can move the mouse to where he wants the character to look again, but it's just an annoying piece of functionality that makes it feel very annoying to turn the camera around, since it will change the rotation of your character as a result and you have to move the mouse back in the direction you want to face again =(
Remember, you don't fail unless you give up trying to succeed!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #3 on: July 28, 2013, 04:47:16 PM »
hi,

 yes, so here, typically, you should simply have you rlook at system take this in consideration instead of trying to work against how unity handled cursor lock.

When you unlock, fire a event to your look at system, and reset its values so that it looks straight ahead. is that possible?

 else, definitly look for working out a system based on relative movements of the mouse instead of an absolute screen position.

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #4 on: July 28, 2013, 05:01:58 PM »
that makes sense with the looking forward after releasing, but that would still probably change the characters rotation after releasing right-click which is what i want to avoid entirely

So far, when you right click, it stops updating the mouse-pick position so when you hold down right-click, the character will keep looking at the point where you had the mouse before you pressed right-click, even if you move the character around using WASD, but when you let go it just snaps to a position that could be forward as you suggest, but the sudden snapping to a different rotation just makes it all feel so "meh"
Remember, you don't fail unless you give up trying to succeed!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #5 on: July 28, 2013, 05:04:35 PM »
Hi,

 do you have a web publish I could play with to see exactly what you mean?

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #6 on: July 29, 2013, 09:21:44 AM »
sure, I will upload one in a few minutes

EDIT:

I just made some changes to it - when you right-click to move the camera, it will now reset the character's position to 0, 0, 0 so it looks straight forward. This works better, however i could still use any advice you would have on making this feel as good as possible:

https://dl.dropboxusercontent.com/u/19886152/Public.html (if you get an error, give it a minute to synch the data file)

Thanks in advance:

PS: Left-click shooting is just a test at the moment, will be replaced soon.

Buildings are enter-able, and that's pretty much the extend of the functionality in the game right now.
« Last Edit: July 29, 2013, 09:46:09 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #7 on: July 29, 2013, 10:39:08 AM »
Hi,

 right click brings the untiy webplayer context, is that normal?

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #8 on: July 30, 2013, 07:13:40 AM »
that's weird! Are you sure you have the game focused first? so left-click the game and make sure you can move around etc, and then right click should unlock the camera for movement

Works fine for me =(
Remember, you don't fail unless you give up trying to succeed!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #9 on: July 30, 2013, 08:02:53 AM »
Hi,

Yeah, I am totally moving and controlling the character, so I am focused. I am on mac if that could be the issue.

bye,

 Jean

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #10 on: July 30, 2013, 11:30:38 AM »
Yes, it might have something to do with the input. I don't know if mouse input is different on mac than on PC but it sounds like that could be the issue. I will take a look at it at some point and bump this thread in a few days :) thanks for your time!
Remember, you don't fail unless you give up trying to succeed!

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #11 on: August 02, 2013, 06:22:45 AM »
Hi Koz

Bit old thread, so Im sure you have fixed this now, just thought I would comment that your game looks very nice so far, I enjoyed walking about your environment.

In regards to your question, I think you have a slightly wrong way of controlling this anyway. Your character walks the direction from input keys not the mouse, that only handles the direction the character is facing. Once you have an animation working this will be obvious (he needs to face the direction of the key commands not the mouse)or he will slide sideways.
BUT this will make shooting impossible wont it? When he is walking (facing) one direction, THEN you click the mouse will he turn imediatly to the mouse and shoot? not good.
Maybe you should change it so that he DOES walk towards the direction of the mouse, (so hes always facing the right way for shooting) and your keys are simply forward and backwards commands?
OR another way would be to use a more 3rd person view, where you use WASD to move (and aim) and the camera just follows from behind, therfore not requiring a right click to re-orient the view (except for tilt perhaps?)

Jean needed to go into fullscreen view to test BTW, as he said in window mode it just brings up right click web window (where he should have selected fullscreen)!

Anyway, looking good, would like to see new versions!

MArk
« Last Edit: August 02, 2013, 06:24:39 AM by markfrancombe »

KozTheBoss

  • Full Member
  • ***
  • Posts: 150
  • You dont fail unless you give up trying to succeed
    • Pixel Life - portfolio
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #12 on: August 02, 2013, 06:47:49 AM »
Hi Mark! :)

Thanks for the kind words! I haven't really solved this yet, but your input is very much appriciated as I am not sure how i want the controls to be yet. I want them to feel good, and my first thought was to make it like a twin-stick shooter (the problem is indeed finding a good control scheme for mouse and keyboard). I have considered the problems that would occur with animations the way it is now, but changing it so W walks forward in relation to where the character is looking would feel very weird. Snapping the camera as a sort of 3rd person view isn't really something i would love to do, as it would take away from the top-down feel of the game, and I am not sure how you would control the character's rotation with the mouse then. (edit: I guess that could work, actually. Still use top-down view but parent the camera to the character model, and when moving the mouse left and right it would simply rotate the character controller? hmm, interesting, I will try making this and will update with a build to see if it feels better :)

The idea of having the character face the way you are walking with WASD except when shooting sounds like it could be a great way to do it, except that the rotation would snap as you mentioned when beginning to shoot =/ I am still twisting my brain to try and come up with a system that could make it work without the current top-down twin-stick feel being removed or diminished.

IF i was to keep the current control scheme, What i think could potentially work is if i put box colliders on the movement portion of the character (invisible GO that always faces same way as the camera, this is what has the WASD movements, and the character model is a child of it) one box on each side of it, and I could then raycast forward or backwards or whatever direction from the character model, and detect which box I am hitting and thereby know which way the character is facing compared to the WASD movement, and use that to play the correct animation depending on which way i am moving.

I havent delved too deep into that, was just an idea I had.

If you have any suggestions for a solution, or for another control scheme that could work, please let me know :) (I had planned on adding controller support, so it would have to work similarly to a controller-operated twin-stick shooter where left stick controls movement according to camera angle, and right stick controls rotation)

thanks again!

-Koz
« Last Edit: August 02, 2013, 06:52:41 AM by KozTheBoss »
Remember, you don't fail unless you give up trying to succeed!

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #13 on: August 02, 2013, 08:16:35 AM »
I suppose it throws up more questions than answers...

Do you want to be able to strafe? Run one way while shooting another? Then maybe WASD (or cursors) is just running direction... (you are right, on a top down, you need to configure WASD to be "points of the compass" directions NOT related to character related, I remember the first Silent Hill games, really annoying that if you are running towards the camera the left right controls were reversed!!!)
SO W needs to take the character UP screen, W left.. unrelated to the character.
Then maybe (just maybe??) The mouse could be for firing direction, so you would need to get into blending animations (or is it masks??) So that legs run one way while upper body swivels to point mouse direction, you would need some restraints here, would be good if you could get it right but I expect... tricky.

I suppose ACTUAL point an click is too childish for you? You know UFO style? click on some ground and he runs there?

Can be pretty cute?

It all depends on you game and audience and feel you want...

But.. hey controllers.. wow.. Aint they just the most tricky bit of the whole game making thing?
 

markfrancombe

  • Sr. Member
  • ****
  • Posts: 338
Re: Mouse Lock - Resets mouse position to screen center?
« Reply #14 on: August 02, 2013, 08:20:50 AM »
Ahh.. I get your aim now, I have to admit that i didnt know the expression "Twin Stick Shooter" So I googled, now I do... I think my "swivel" idea is what you mean right?
Good discussion here, maybe you seen it?

http://www.gamasutra.com/view/feature/6323/a_guide_to_ios_twin_stick_shooter_.php?print=1