Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Middle Mouse Button Use

Recommended Posts

I'm in the process of developing a RTS camera script in the style of Command and Conquer. 

So far I've modified the spectator script so that if you move the mouse to the top of the screen the camera moves forward. If you move the mouse to the bottom of the screen the camera moves backwards. Likewise if the mouse moves left or right the camera follows. I've even got the height of the camera linked to the mouse wheel. 

What I would like to do is to rotate the camera by pressing the middle mouse button and moving the mouse in the direction I want the camera to rotate.

local mhit = window:MouseDown(Key.MButton)

This code lets me know the Middle button is pressed but how do I get the Left - Right information at the same time?

Link to post
13 hours ago, Thirsty Panther said:

local mhit = window:MouseDown(Key.MButton)

This code lets me know the Middle button is pressed but how do I get the Left - Right information at the same time?

Just like you would for any other time for the camera rotation but make the middle mouse button the qualifier for allowing the camera to rotate. Look at the orbital camera example I posted almost two years ago for an example: 

Here's the same code updated to show the use with middle mouse button instead of the right mouse button:

window = Window:Create("Orbital Camera",0,0,800,600,Window.Titlebar+Window.Center)
context = Context:Create(window)
world = World:Create()
camera = Camera:Create()
light = DirectionalLight:Create()

player = Model:Load("Models/Characters/generic/generic.mdl")
pivot = Pivot:Create()

mx = 0
my = 0
prevmx = 0
prevmy = 0
toggle = 0

while window:KeyDown(Key.Escape)==false do
	if window:Closed() then break end
	if window:MouseHit(Key.MButton) then toggle = 1 end
	if window:MouseDown(Key.MButton) then
		mousepos = window:GetMousePosition()
		mx = pivot:GetRotation().x + (mousepos.y-prevmy)
		my = pivot:GetRotation().y + (mousepos.x-prevmx)
		if toggle==1 then
			toggle = 0
			mx = pivot:GetRotation().x
			my = pivot:GetRotation().y
		prevmx = mousepos.x
		prevmy = mousepos.y

	context:DrawText(string.format("FPS: %.1f",Time:UPS()), 2, 2)
	context:DrawText("Hold Middle Mouse Button Down to Rotate", 2, 22)


  • Like 1
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Facebook Twitter Youtube Github Steam
  • Create New...