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: Raycast

Previous Thread :: Next Thread 
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 03:18 PM
I want it so when one brick touches another a raycast will fire out of a brick towards the brick that touched the brick. Here is what i have so far

local Shooter = script.Parent
local Radius = script.Parent.Parent.Radius

Radius.Touched:connect(function(hit)
local ray = Ray.new(Shooter, hit)
local hit, position = game.Workspace:FindPartOnRay(ray, hit)

local distance = (position - Shooter.Position).magnitude
local rayPart = Instance.new("Part", Shooter)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(position, Shooter.Position) * CFrame.new(0, 0, -distance/2)

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 5)
end)
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 03:37 PM
b
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 03:54 PM
b
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:06 PM
b
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Mar 2015 04:08 PM
local ray = Ray.new(Shooter.Position, (hit.Position - Shooter.Position).unit)
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:10 PM
Thanks, no errors but it doesnt draw a ray
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:13 PM
The ray is being created but is not visible, something wrong with distance or position?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:15 PM
Distance is the dodgy variable, i did some debugging but i dont know how to fix it
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:22 PM
b
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:38 PM
b
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Mar 2015 04:48 PM
It only changes the position on the Z axis. You want to get the midpoint of all three axes separately and set the position to that.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 04:52 PM
Sorry, i got no sense of that(im an idiot) In lua what would that be like?
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
07 Mar 2015 05:11 PM
King, his code is correct on all axes as far as I can see.
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Mar 2015 05:15 PM
> King, his code is correct on all axes as far as I can see.
> ... * CFrame.new(0, 0, -distance/2)

That moves it only to the midpoint of the Z axis.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 05:38 PM
What are you suggesting?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 06:03 PM
b
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
07 Mar 2015 06:14 PM
*Facepalm*
It only NEEDS to be moved to the midpoint on the Z axis. It is already at the midpoint on the others.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
07 Mar 2015 06:21 PM
So what i have is already correct?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
07 Mar 2015 09:27 PM
> It only NEEDS to be moved to the midpoint on the Z axis. It is already at the midpoint on the others.

What the heck are you talking about? He currently sets it at the position it hit at and then arbitrarily messes with the Z axis. If I shoot it straight down the X axis with a distance of 50, it will go to the position that it hit and then 25 studs to the left, nowhere near where it's supposed to be.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 04:49 AM
SO HOW DO I FIX THIS?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 05:19 AM
b
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 05:31 AM
b
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
08 Mar 2015 05:32 AM
Radius.Touched:connect(function(hit)
local ray = local ray = Ray.new(Shooter.Position, (hit.Position - Shooter.Position).unit)
local hit, position = game.Workspace:FindPartOnRay(ray, hit)

local distance = (position - Shooter.Position).magnitude
local rayPart = Instance.new("Part", Shooter)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(Vector3.new(), Shooter.Position- position) + (Shooter.Position+ position)/2

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 5)
end)
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
08 Mar 2015 05:35 AM
Still no ray beign drawn local Shooter = script.Parent.Parent.Shooter
local Radius = script.Parent

Radius.Touched:connect(function(hit)
print("Worked")
local ray = Ray.new(Shooter.Position, (hit.Position - Shooter.Position).unit)
local hit, position = game.Workspace:FindPartOnRay(ray, hit)

local distance = (position - Shooter.Position).magnitude
local rayPart = Instance.new("Part", Shooter)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(Vector3.new(), Shooter.Position- position) + (Shooter.Position+ position)/2

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 5)
end)
Report Abuse
Casualist is not online. Casualist
Joined: 26 Jun 2014
Total Posts: 4443
08 Mar 2015 05:44 AM
local Shooter = script.Parent.Parent.Shooter
local Radius = script.Parent
local maxDistance = 100
Radius.Touched:connect(function(hit)
print("Worked")
local ray = Ray.new(Shooter.Position, (hit.Position - Shooter.Position).unit*maxDistance)
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(ray, {Shooter})
print(hit, position)
local distance = (position - Shooter.Position).magnitude
local rayPart = Instance.new("Part", Shooter)
rayPart.Name = "RayPart"
rayPart.BrickColor = BrickColor.new("Bright red")
rayPart.Transparency = 0.5
rayPart.Anchored = true
rayPart.CanCollide = false
rayPart.TopSurface = Enum.SurfaceType.Smooth
rayPart.BottomSurface = Enum.SurfaceType.Smooth
rayPart.formFactor = Enum.FormFactor.Custom
rayPart.Size = Vector3.new(0.2, 0.2, distance)
rayPart.CFrame = CFrame.new(Vector3.new(), Shooter.Position- position) + (Shooter.Position+ position)/2

--add it to debris so it disappears after 0.1 seconds
game.Debris:AddItem(rayPart, 5)
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