mouse.Hit problems with an isometric camera

Hallo!

I have started to work on a game utilising an isometric camera.

I want the game to be pretty mouse influenced eg: You attack where your mouse is; Move towards where your mouse is; etc.
The problem I have encountered is that mouse.Hit doesn’t really work properly when the camera is in a isometric perspective.

It may be that the mouse.Hit doesn’t register correctly on big distances from the camera, since the only way I could replicate an orthographic-like perspective was to move the camera really far, and then make the field of view really low.

Using this script I am now trying to rotate the player towards the mouse:

local mouse = player:GetMouse()
	
humanoid.RootPart.CFrame = CFrame.lookAt(
	humanoid.RootPart.Position,
	Vector3.new(
		mouse.Hit.Position.X,
		humanoid.RootPart.Position.Y,
		mouse.Hit.Position.Z
	)
)

This works wonderful when the isometric camera is not enabled but as soon as it is it gives me this result:


The red block is moving where the mouse.Hit returns, it’s obviously not where the mouse actually is

I have even tried to shoot a ray from the camera to the mouse, and then get the closest points from the ray to the HumanoidRootPart:

local mousePos = game:GetService("UserInputService"):GetMouseLocation()

local mouseRay = workspace.CurrentCamera:ViewportPointToRay(mousePos.X, mousePos.Y)
local closestPoint = (mouseRay.Origin - humanoid.RootPart.Position) - (mouseRay.Origin - humanoid.RootPart.Position):Dot(mouseRay.Direction.Unit) * mouseRay.Direction.Unit
 
local virtualMousePosition = humanoid.RootPart.Position + closestPoint

I really don’t know how to fix this and I would hope for some sort of feedback, thanks!

1 Like

Mouse.Hit is not compatible with isometric cameras. One possibility is to switch the stepping method, but that might cause stuttering. You should raycast to your desired point instead.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.