Temporarily lock camera rotationwhile holding left click on object

I know that’s a long title but I can explain the issue. I’m trying to make it where when the player clicks and holds LMB on a dial, the camera’s rotation will lock in place (as it don’t move other than rotation anyways). During this the player can either move their mouse left or right which will rotate the dial relative to its position clockwise or couter-clockwise.

Any ideas on how to do this? I’m currently just using a Movement Mouse logic block connected to the camera for Visibility and Look Mouse. The two logic blocks I have on the dial (not connected to anything as of yet) are a Mouse Over block and a Left Click with a True Pulse mode on.

Any further questions for clarification are welcome.

use the message sensor on your mouselook which looks for “INTERACT”. then on all interact objects, if mouse over, send message “INTERACT”.

this is kind of a guess since i dont use logic bricks beyond Always-Python

I’m up for using Python, I’m just very new to it. As in I’m learning it some what while doing this game and not 100% understanding everything completely.

the python method would be using a raycast instead of a mouse over. then, have the raycast search if the object has an “INTERACT” property. if so, and the left mouse is down, disable the mouselook code and show the cursor or a UI element.

Did you mean something kind of like this?

PS: Controls are Mouse movement and LMB

Attachments

MouseLookClock_00.blend (643 KB)

YES! YES! EXACTLY!!! Thank you so much John!!!

You’re quite welcome, but that was just a quick example to know what you were looking for. The actual implementation should be a bit more refined.

Yeah, I mutated it a bit and got it where while the mouse is over the dial and when the player clicks and holds LMB then the camera locks. As soon as they release LMB the mouse unlocks! :o

Excellent! Hurrah! One is glad to have been of service :slight_smile:

Looking forward to you future works ; )

You wouldn’t happen to know how to read the rotation of an object in python would you John? I’ve been tinkering around but I don’t think I’m doing it right. Now that the object is rotating, I want it to take the rotation and change a float property dependent on the rotation. If not it’s fine :smiley:

Never mind, figured it out.

That’s the spirit! : D Just out of curiosity; how did you solve it?

Two simple scripts, actually. First things first you have to create a property that can record the rotation while playing. You can either use a float or integer. Just note that if you want a number to be within a range, the best solution is to set the object’s rotation is on 1 on the axis you want, that way when you do the lock the way you did you set the min to 1 so that it is not infinite (0 is infinite, as you know).
This script goes on the object you want to record the rotation of connected only to an Always sensor with the “True Pulse” mode activated:


import bge, math

cont = bge.logic.getCurrentController()
own = cont.owner

xyz = own.localOrientation.to_euler()
rotz = math.degrees(xyz[2])
own["rotation property"] = abs(185 - rotz) #not required if you only want to mimic rotation

Note that on the last line, I made the rotation property equal to the absolute of 185 - the rotation of the z axis. This is what I needed. Change rotz with rotx or roty for their respective rotation reads. I wanted my dial to calculate when rotated clockwise, it goes up, and when counterclockwise, it goes down. That’s why the “-”.

This next script goes on the text object with an Always sensor with the “True Pulse” mode activated:


import bge

scene = bge.logic.getCurrentScene()

object = scene.objects["object"]["rotation property"]
display = scene.objects["text object"] 

display.resolution = 4
display.text = str(object)

“display.resolution = 4” makes text object look better and not like a blur. Not entirely needed, but it helps.
“display.text = str(object)” makes the text of text object equal to the rotation property referenced in the previous script. You MUST put “str(object)” or it won’t work. You must implicitly tell Blender/Python that you want the interval to be translated to a string or else the script will fail to work.

If you have any more questions, please let me know! I am more than happy to help :smiley: