My click to animate, drag to rotate conundrum (SOLVED)

I struggle a bit with the following prob:
If the user clicks on an image, an animation starts that moves him closer. If he drags the mouse, he starts to rotate.
Now, if he would like to rotate but the input starts on an image, the animation will start, since the click is always first.

So, at the moment, I delay the animation a little bit like so:

function on_input(self, action_id, action)	
	if action_id == TOUCH then
		local pos = vmath.vector3(action.x, action.y, 0)
		local cam_pos = go.get_position("camera")
		
		if action.pressed then
			self.pressed_position = pos
			self.pressed = true
		end
		
		if self.pressed then
			local distance = vmath.length(pos - self.pressed_position)
			-- do not perform a raycast when the player rotates:
			-- if distance <= 20, it's a click and raycasting is allowed
			if distance <= 20 then
				-- only cast a ray when the camera is not raised to look at a painting
				if cam_pos.y == self.camera_init_pos_y then
					click_counter = click_counter + 1
					if click_counter > 12 then
						-- code for ray casting, if it hits an image, the animation starts
					end
				end	
			end
		end	
		-- code to reset the counter and other variables on release	
	end
	-- code for keyboard input
end

This effectively means a click and hold and the user needs to press longer and harder. This might be a bit irritating.

I could avoid this problem with a FPS rotation where the user rotates when he moves the mouse.
Personally, I don’t like this very much and, personal preferences aside, I don’t think it works too well for my project, way too hectic.

Can someone think of an alternative? I don’t think there is one - but you never now.

I’m guessing this is to do with the art museum tour? If so, maybe triggering the closeup on release, rather than press, could work?

5 Likes

@totebo, super idea! I always forget that I could run the code on release. too. :flushed: Thank you, will try this immediately.

And yes, you guessed right :grinning:

2 Likes

It works, it works :partying_face: Thank you so much, @totebo!

The code looks like this now:

function on_input(self, action_id, action)	
	if action_id == TOUCH then
		local pos = vmath.vector3(action.x, action.y, 0)
		local cam_pos = go.get_position("camera")
		
		if action.pressed then
			self.pressed_position = pos
			self.pressed = true
		end
		
		if self.pressed then
			local distance = vmath.length(pos - self.pressed_position)
			-- do not perform a raycast when the player rotates:
			-- if distance <= 20, it's a click and raycasting is allowed
			if distance <= 20 then
				start_point = action.x
				end_point = action.y
				self.click = true
			elseif distance > 20 then
				self.click = false
			end
		end	
		if action.released then
			if cam_pos.y == self.camera_init_pos_y and self.click then
				-- cast the ray
			end				
			-- other stuff
		end
	end
	-- code for keyboard input
end
3 Likes

Great, glad to help! :partying_face:

2 Likes