|
| 29 Mar 2016 04:18 AM |
I'm trying to raycast based on how the block is rotated, but the problem is that the raycast seem to only go one direction. What do I do?
function RayMake() local x = 0 local y = 0 for i = 0, 64 do if x == 10 then y = y + 1 x = 0 else x = x + 1 end local ray = Ray.new(Head.CFrame.p,(Head.CFrame * CFrame.new(-5 + x,0 -y,-1).p).unit*100) print(x,y) for i, v in pairs(game.Workspace:GetChildren()) do if v.Name == "Block" then ignore = v end end local hit, position = game.Workspace:FindPartOnRay(ray, ignore) print(hit, position) if hit.Parent:FindFirstChild("Humanoid") then target = hit.Parent end end end |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 04:20 AM |
| I noticed my first statement isn't so informative. Let me rephrase. The block raycasts a ray that is directed infront of the brick. The problem is that if I were to rotate the brick and raycast it again, it doesn't raycast infront of the brick. |
|
|
| Report Abuse |
|
|
Kryddan
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 310 |
|
|
| 29 Mar 2016 04:30 AM |
| ray.new is Vector3 based not CFrame so Head.CFrame * CFrame.new() will not work. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 05:04 AM |
| Yes, that's why I added .p in the end. Any solutions, guys? |
|
|
| Report Abuse |
|
|
Kryddan
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 310 |
|
|
| 29 Mar 2016 05:34 AM |
Well you didn't...
local ray = Ray.new(Head.CFrame.p,(Head.CFrame * CFrame.new(-5 + x,0 -y,-1).p).unit*100)
should local ray = Ray.new(Head.CFrame.p,(Head.CFrame.p * Vector3.new(-5 + x,0 -y,-1).p).unit*100) |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 05:50 AM |
local ray = Ray.new(Head.CFrame.p,Head.CFrame.lookVector*100)
I know that isn't what you wanted to do, but start with that. You weren't using lookVector previously. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 29 Mar 2016 06:12 AM |
Was about to post, but noticed Jarod had it right.
"My Life is going Good... but..." |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 07:05 AM |
I'm a little confused. Are you only casting forward? Are you trying to cast from all faces of the part?
|
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 07:13 AM |
| Thanks Jarod for the reply. My Ray now has a direction. Right now I'll work on how to make it work for the older calculations. Thanks guys. |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 07:22 AM |
| Wait, how the rays look like is hard, how do I make the rays visible? I need some help there. |
|
|
| Report Abuse |
|
|
Kryddan
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 310 |
|
|
| 29 Mar 2016 08:17 AM |
Something like this for the ray, bullet in this case:
local bullet = Instance.new("Part", workspace) --Part
bullet.BrickColor = BrickColor.new("Yellow") bullet.FormFactor = "Custom" bullet.Material = "Plastic" bullet.BackSurface = "Smooth" bullet.BottomSurface = "Smooth" bullet.FrontSurface = "Smooth" bullet.LeftSurface = "Smooth" bullet.RightSurface = "Smooth" bullet.TopSurface = "Smooth" bullet.Transparency = 0 bullet.Locked = true bullet.Anchored = true bullet.CanCollide = false bullet.Name = "Bullet"
This for the position of it and the size.
local origin = origin -- change to where the ray starts from, in your case Head.CFrame.p local pos = pos -- this would be your ending position local time = time -- how many seconds the bullet will exist local distance = (origin - pos).magnitude bullet.Size = Vector3.new(0.2,0.2,distance) bullet.CFrame = CFrame.new(origin,pos) * CFrame.new(0,0, -distance / 2)
game:GetService("Debris"):AddItem(bullet, time) |
|
|
| Report Abuse |
|
|
|
| 29 Mar 2016 08:26 AM |
Okay, I have no idea what you're trying to do, but to cast a ray from all the faces of a part, do:
local part = game.Workspace.Part for _, normalId in pairs(Enum.NormalId:GetEnumItems()) do local normal = Vector3.FromNormalId(normalId) local pos1 = part.CFrame.p local pos2 = part.CFrame * normal local dir = pos2 - pos1 local ray = Ray.new(pos1, dir * 1000) end |
|
|
| Report Abuse |
|
|