To cast a ray, you use the workspace:Raycast() function.
The parameters for this is the origin, direction, and a RaycastParams.
To make a RaycastParams, just do local params = RaycastParams.new() and set the values of it.
The values are: FilterDescendantsInstances, which is a table of Instances you want to filter from the raycasting,
FilterType is an Enum.RaycastFilterType and is either Whitelist or Blacklist.
Whitelist means that the ray can only detect things in the FilterDescendantsInstances, and Blacklist means that the ray can detect everything except the FilterDescendantsInstances.
It also has IgnoreWater, which is a bool value you set to true if you want the ray to ignore water terrain.
Lastly, CollisionGroup. "Parts in collision groups that are set to not collide with this group will be ignored". You do not have to set this value. If you don't it defaults to the default collision group.
The Raycast() function returns a RaycastResult, which holds the position of where the ray hit the part (result.Position), the instance it hit (result.Instance), the material of the instance (result.Material), and the normal direction of the face it hit (result.Normal). That is basically just the direction it's facing.
To raise the position of the origin point, just add a Vector3 to your original.
The Vector3 will be: Vector3.new(0, amount, 0, amount being however many studs you want the origin to be raised.
So, you would do origin = HRP.Position + Vector3.new(0, amount, 0)
Since the head is 1.5 studs over the center of the HRP, you would add Vector3.new(0, 1.5, 0)
And, you should also make sure you ignore the head of the player.
1 comment