generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Raycasting Help

Previous Thread :: Next Thread 
SneakySecretAgent is not online. SneakySecretAgent
Joined: 28 Sep 2011
Total Posts: 323
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
SneakySecretAgent is not online. SneakySecretAgent
Joined: 28 Sep 2011
Total Posts: 323
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 is not online. 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
SneakySecretAgent is not online. SneakySecretAgent
Joined: 28 Sep 2011
Total Posts: 323
29 Mar 2016 05:04 AM
Yes, that's why I added .p in the end. Any solutions, guys?
Report Abuse
Kryddan is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
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
SneakySecretAgent is not online. SneakySecretAgent
Joined: 28 Sep 2011
Total Posts: 323
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
SneakySecretAgent is not online. SneakySecretAgent
Joined: 28 Sep 2011
Total Posts: 323
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 is not online. 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
direMitten is not online. direMitten
Joined: 18 Jun 2015
Total Posts: 1294
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image