Me and a friend are working on a blood script at the moment, with blood pools and particles using raycasting. We want to have a ray shoot in front of the player and then downwards for the blood pools. How could we do this?
You can get a unit vector in the direction of the player with Player.Character.HumanoidRootPart.CFrame.LookVector
. Use that for your first cast. The second cast would be in the direction Vector3.new(0, -1, 0)
.
(You’ll need to multiply both of those by however far you want the ray to travel)
Both would start at the player’s root part’s position, assuming that’s what you want.
Add the character to the ignore list, and follow this tutorial for details about how raycasting works.
Thank you for the response, we will try this!
Yes but, is it like velocity when you use lookVector?
You wouldn’t need to cast for the forward, simply originate the raycast from in front of the player using LookVector
Show an example? please? [30 chars]
You want blood pools on the floor I assume,
you can use
local r = Ray.new(humanoidrootpart.Position,humanoidrootpart.Position-Vector3.new(0,10,0))
then use workspace:FindPartOnRay() to get what it touched which would be the ground. the second parameter is the position
local h,p = workspace:FindPartOnRay(r)
print(h,p)
I don’t exactly understand what you mean by in front then down, you can always change the zeroes in the first script to create pools of blood in different areas below the player
I am the person thats working with wowland and we are needing a script that just go infront say like LookVector*5 which is infront of the player 5+ Steps Increase Infront and we want the splat to be on the floor sticked and at the position infront of the player.
In that case @plasmascreen is correct. You only need one ray. The most basic form of this:
-- assuming "rootPart" is the HumanoidRootPart of the player
local rayOrigin = rootPart.Position + rootPart.CFrame.LookVector*5
local rayDirection = Vector3.new(0, -10, 0)
local raycastResult = workspace:Raycast(rayOrigin, rayDirection)
is Workspace:Raycast() Different than FindPartOnRay?
Workspace:Raycast
is what ROBLOX recommends you use now. It replaces FindPartOnRay
. It gives you more information than just the position and part. Details are in the article I originally linked.
If you prefer FindPartOnRay
, use that, it still works fine.
Alright thanks, wowland is currently busy at the moment but thanks for the tip ill tell him! WOW, its actually working Thanks alot! Like thank you! Credit to you Ill tell wowland this is the solution!
It seems to work, although the ray isnt accurate meaning the ray will follow the roots pos random times and not to the floor.
Can you please elaborate on the problem?
robloxapp-20200903-2017581.wmv (3.1 MB) As you can see its glitching around also the lookvector also isnt accurate when im trying to make the velocity of the blood trail part LookVector*choose value for the lookvector multiplication
LookVector and Raycast are always going to be accurate, but they are dependent on what you give them as inputs.
Did you add the character model and the parts that make up the blood to the ignore list of the raycast?
No, i forgot, show me and example?
The article I linked has an example of blacklisting objects from the raycast:
I can’t give much more details without knowing more about your setup.
Ok it works now Thanks! Alot []