Produce a value by Utilizing 2 CFrames

I want to get the CFrame of the HumanoidRootPart and Mouse.hit and produce one value that changes relative to how high or low the Mouse is relative to the HumanoidRootPart.
The value needs to have a Min and Max value. I have tried some solutions and utterly failed. I can’t use the 2d mouse position if you are wondering.

All help would be appreciated.

Edit: The Mouse.Hit will always be in front of the player.

Show code

There is no code, I can’t think of a way to achieve this. There are multiple problems I have run into.

local LocalPlayer = game:GetService("Players").LocalPlayer
local Mouse = LocalPlayer:GetMouse()

local Character = script.Parent

	if Mouse.Hit then
		local HRPCFrame = Character.HumanoidRootPart.CFrame 
		local MouseCFrame = Mouse.Hit

I have been trying all types of methods on a baseplate.

Take both cframe values, get their relative offset with the camera’s cframe, and then you can grab the difference of the y heights, which would generate a value from -x to x. You cannot produce a min and max with this method alone though, so it’d be best to just utilize screen space for establishing your limits.

To be quite clear, what you’re asking for is pretty vague. I wasn’t sure whether you meant “high or low” in terms of what the screen sees, or if you meant world space Y height.

I want a stable way to measure the mouse position only on the Y axis, due to the camera being locked I can’t use screen space. I also want to avoid using the camera because the y value of the camera is not constant. Edit: I can’t quite articulate myself correctly since I can’t describe very well what I mean.

You can simply subtract the Mouse’s position with the RootPart’s to get the difference.

local Y: number = Mouse.Hit.Y - RootPart.Position.Y

However, there are some specifics to implementation here. What is exactly is your use-case?

Thank you, you saved me, I can work with that value and implement a method to get a max/min value!

1 Like

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