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: RayRendering issue; not positioning where mouse is clicked.

Previous Thread :: Next Thread 
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 10:49 AM
I am no good when it comes to CFraming and I cannot seem to get this to work as intended. I am using a couple of pages from the Wiki: http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun and http://wiki.roblox.com/index.php?title=Ray but it still doesn't help with my issue. The issue is that the tool's beam isn't coming out in the right angle.

Script:

-- LocalScript inside a tool.
local Services = {
Players = game:GetService("Players");
Debris = game:GetService("Debris");
RunService = game:GetService("RunService");
InputService = game:GetService("UserInputService");
};
local Main = {
Tool = script.Parent;
Player = Services.Players.LocalPlayer;
Handle = script.Parent.Handle;
LaserShooter = script.Parent.LaserShooter;
LaserEye = script.Parent.LaserEye; -- This one isn't really needed, you don't have to use this.
Mouse = Services.Players.LocalPlayer:GetMouse()
};
local States = {
["ToolActive"] = false;
["BeamMode"] = false;
};
local Key = {
[Enum.KeyCode.F] = false;
};
repeat wait() until Main.Player.Character ~= nil
function ActivateTool()
if not States["ToolActive"] then
wait(1)
States["ToolActive"] = true
end
end
function DeactivateTool()
if States["ToolActive"] then
States["ToolActive"] = false
end
end
function FireLaser()
if Key[Enum.KeyCode.F] == true then
if States["BeamMode"] and States["ToolActive"] then
local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
local Mesh1 = Instance.new("CylinderMesh")
local Mesh2 = Instance.new("CylinderMesh")
Mesh1.Parent, Mesh2.Parent = Beam1, Beam2
Mesh1.Scale, Mesh2.Scale = Vector3.new(1, 1, 1), Vector3.new(1, 1, 1)
Beam1.BrickColor, Beam2.BrickColor = BrickColor.new("Institutional white"), BrickColor.new("Institutional white")
Beam1.FormFactor, Beam2.FormFactor = Enum.FormFactor.Custom, Enum.FormFactor.Custom
Beam1.Material, Beam2.Material = Enum.Material.Neon, Enum.Material.Neon
Beam1.Transparency, Beam2.Transparency = 0.75, 0.50
Beam1.Anchored, Beam2.Anchored = true, true
Beam1.Locked, Beam2.Locked = true, true
Beam1.CanCollide, Beam2.CanCollide = false, false
Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)
Services.Debris:AddItem(Beam1, 10) Services.Debris:AddItem(Beam2, 10)
end
elseif Key[Enum.KeyCode.F] == false then
print("Not active");
end
end
Main.Tool.Equipped:connect(ActivateTool)
Main.Tool.Unequipped:connect(DeactivateTool)
Main.Tool.Activated:connect(FireLaser)
Services["InputService"].InputBegan:connect(function(InputObject, GameEvent)
if not GameEvent then
if Key[InputObject.KeyCode] == false then
if not States["BeamMode"] and States["ToolActive"] then
Key[InputObject.KeyCode] = true
States["BeamMode"] = true
print(Key[InputObject.KeyCode])
elseif States["BeamMode"] and States["ToolActive"] then
Key[InputObject.KeyCode] = true
States["BeamMode"] = false
Key[InputObject.KeyCode] = false
print(Key[InputObject.KeyCode])
end
end
end
end)


-=[ RAP: 287,436 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 10:51 AM
Oops, replace the FireLaser with this, I accidentally left out something in it.

function FireLaser()
if Key[Enum.KeyCode.F] == true then
if States["BeamMode"] and States["ToolActive"] then
local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
local Mesh1 = Instance.new("CylinderMesh")
local Mesh2 = Instance.new("CylinderMesh")
Mesh1.Parent, Mesh2.Parent = Beam1, Beam2
Mesh1.Scale, Mesh2.Scale = Vector3.new(1, 1, 1), Vector3.new(1, 1, 1)
Beam1.BrickColor, Beam2.BrickColor = BrickColor.new("Institutional white"), BrickColor.new("Institutional white")
Beam1.FormFactor, Beam2.FormFactor = Enum.FormFactor.Custom, Enum.FormFactor.Custom
Beam1.Material, Beam2.Material = Enum.Material.Neon, Enum.Material.Neon
Beam1.Transparency, Beam2.Transparency = 0.75, 0.50
Beam1.Anchored, Beam2.Anchored = true, true
Beam1.Locked, Beam2.Locked = true, true
Beam1.CanCollide, Beam2.CanCollide = false, false
Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)
Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2), CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2)
--Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0), CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0)
Services.Debris:AddItem(Beam1, 10) Services.Debris:AddItem(Beam2, 10)
end
elseif Key[Enum.KeyCode.F] == false then
print("Not active");
end
end


-=[ RAP: 287,405 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 10:57 AM
Anyone? ;/


-=[ RAP: 287,414 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
cgjnm is not online. cgjnm
Joined: 22 Dec 2011
Total Posts: 2347
01 May 2016 11:00 AM
Way too much to read
Report Abuse
Fall3nGod is not online. Fall3nGod
Joined: 30 Jan 2014
Total Posts: 1323
01 May 2016 11:02 AM
ikr
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 11:54 AM
The issue is in this function below, I was just putting the whole code there so you can take it yourself so you may test it.

function FireLaser()
if Key[Enum.KeyCode.F] == true then
if States["BeamMode"] and States["ToolActive"] then
local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
local Mesh1 = Instance.new("CylinderMesh")
local Mesh2 = Instance.new("CylinderMesh")
Mesh1.Parent, Mesh2.Parent = Beam1, Beam2
Mesh1.Scale, Mesh2.Scale = Vector3.new(1, 1, 1), Vector3.new(1, 1, 1)
Beam1.BrickColor, Beam2.BrickColor = BrickColor.new("Institutional white"), BrickColor.new("Institutional white")
Beam1.FormFactor, Beam2.FormFactor = Enum.FormFactor.Custom, Enum.FormFactor.Custom
Beam1.Material, Beam2.Material = Enum.Material.Neon, Enum.Material.Neon
Beam1.Transparency, Beam2.Transparency = 0.75, 0.50
Beam1.Anchored, Beam2.Anchored = true, true
Beam1.Locked, Beam2.Locked = true, true
Beam1.CanCollide, Beam2.CanCollide = false, false
Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)
Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2), CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2)
--Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0), CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0)
Services.Debris:AddItem(Beam1, 10) Services.Debris:AddItem(Beam2, 10)
end
elseif Key[Enum.KeyCode.F] == false then
print("Not active");
end
end


-=[ RAP: 287,324 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 11:57 AM
;/


-=[ RAP: 287,353 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Silicti is not online. Silicti
Joined: 07 Nov 2012
Total Posts: 8242
01 May 2016 11:57 AM
hi lester
ill check it out and pm you ok
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 11:59 AM
I don't know who this "Lester" guy is, but okay? 0_o


-=[ RAP: 287,353 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 12:04 PM
Another bump..


-=[ RAP: 287,393 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Silicti is not online. Silicti
Joined: 07 Nov 2012
Total Posts: 8242
01 May 2016 12:09 PM
-- LocalScript inside a tool.
local Services = {
Players = game:GetService("Players");
Debris = game:GetService("Debris");
RunService = game:GetService("RunService");
InputService = game:GetService("UserInputService");
};
local Main = {
Tool = script.Parent;
Player = Services.Players.LocalPlayer;
Handle = script.Parent.Handle;
LaserShooter = script.Parent.LaserShooter;
LaserEye = script.Parent.LaserEye; -- This one isn't really needed, you don't have to use this.
Mouse = Services.Players.LocalPlayer:GetMouse()
};
wait(1)
local States = {
["ToolActive"] = false;
["BeamMode"] = false;
};
local Key = {
[Enum.KeyCode.F] = false;
};
repeat wait() until Main.Player.Character ~= nil
function ActivateTool()
if not States["ToolActive"] then
wait(1)
States["ToolActive"] = true
end
end
function DeactivateTool()
if States["ToolActive"] then
States["ToolActive"] = false
end
end
function FireLaser()
print("Debug 1")
if Key[Enum.KeyCode.F] == true then
if States["BeamMode"] and States["ToolActive"] then
local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
local Mesh1 = Instance.new("CylinderMesh")
local Mesh2 = Instance.new("CylinderMesh")
Mesh1.Parent, Mesh2.Parent = Beam1, Beam2
Mesh1.Scale, Mesh2.Scale = Vector3.new(1, 1, 1), Vector3.new(1, 1, 1)
Beam1.BrickColor, Beam2.BrickColor = BrickColor.new("Institutional white"), BrickColor.new("Institutional white")
Beam1.FormFactor, Beam2.FormFactor = Enum.FormFactor.Custom, Enum.FormFactor.Custom
Beam1.Material, Beam2.Material = Enum.Material.Neon, Enum.Material.Neon
Beam1.Transparency, Beam2.Transparency = 0.75, 0.50
Beam1.Anchored, Beam2.Anchored = true, true
Beam1.Locked, Beam2.Locked = true, true
Beam1.CanCollide, Beam2.CanCollide = false, false
Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)
Services.Debris:AddItem(Beam1, 10) Services.Debris:AddItem(Beam2, 10)
end
elseif Key[Enum.KeyCode.F] == false then
print("Not active");
print("Debug 2")
end
end
Main.Tool.Equipped:connect(ActivateTool)
Main.Tool.Unequipped:connect(DeactivateTool)
Main.Tool.Activated:connect(FireLaser)
Services["InputService"].InputBegan:connect(function(InputObject, GameEvent)
if not GameEvent then
if Key[InputObject.KeyCode] == false then
if not States["BeamMode"] and States["ToolActive"] then
Key[InputObject.KeyCode] = true
States["BeamMode"] = true
--print(Key[InputObject.KeyCode])
print("Debug 3")
elseif States["BeamMode"] and States["ToolActive"] then
Key[InputObject.KeyCode] = true
States["BeamMode"] = false
Key[InputObject.KeyCode] = false
print(Key[InputObject.KeyCode])
end
end
end
end)
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
01 May 2016 12:13 PM
open up a team edit
Report Abuse
Silicti is not online. Silicti
Joined: 07 Nov 2012
Total Posts: 8242
01 May 2016 12:14 PM
do you think you could invite me to a team create so i can see what the tool does, and then try to edit it from there
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 12:18 PM
Uh, this is what needs changing..

function FireLaser()
if Key[Enum.KeyCode.F] == true then
if States["BeamMode"] and States["ToolActive"] then
local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
local Mesh1 = Instance.new("CylinderMesh")
local Mesh2 = Instance.new("CylinderMesh")
Mesh1.Parent, Mesh2.Parent = Beam1, Beam2
Mesh1.Scale, Mesh2.Scale = Vector3.new(1, 1, 1), Vector3.new(1, 1, 1)
Beam1.BrickColor, Beam2.BrickColor = BrickColor.new("Institutional white"), BrickColor.new("Institutional white")
Beam1.FormFactor, Beam2.FormFactor = Enum.FormFactor.Custom, Enum.FormFactor.Custom
Beam1.Material, Beam2.Material = Enum.Material.Neon, Enum.Material.Neon
Beam1.Transparency, Beam2.Transparency = 0.75, 0.50
Beam1.Anchored, Beam2.Anchored = true, true
Beam1.Locked, Beam2.Locked = true, true
Beam1.CanCollide, Beam2.CanCollide = false, false
Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)
Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2), CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2)
--Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0), CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, Distance / 2, 0)
Services.Debris:AddItem(Beam1, 10) Services.Debris:AddItem(Beam2, 10)
end
elseif Key[Enum.KeyCode.F] == false then
print("Not active");
end
end


-=[ RAP: 287,420 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 12:19 PM
Or more specifically, this part:

Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2), CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 2)


-=[ RAP: 287,420 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Silicti is not online. Silicti
Joined: 07 Nov 2012
Total Posts: 8242
01 May 2016 12:19 PM
yeah, but its hard to see whats wrong or test it without the parts that are needed, like the handle, etc
Report Abuse
Silicti is not online. Silicti
Joined: 07 Nov 2012
Total Posts: 8242
01 May 2016 12:21 PM
try

Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 4), CFrame.new(Main.LaserShooter.CFrame.p - Vector3.new(0, 0, 0), Position) * CFrame.new(0, 0, -Distance / 4)
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
01 May 2016 12:23 PM

Beam1.CFrame, Beam2.CFrame = CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, 0, -Distance / 2), CFrame.new(Main.LaserShooter.CFrame.p, Position) * CFrame.new(0, 0, -Distance / 2)

I'm not sure, this is the most I can fix right now.
Also, why'd you try to subtract CFrame.p by Vector3.new(0, 0, 0)? Wouldn't it have no effect?
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 12:30 PM
Yikes, neither one works. This is why I hate messing with CFrames..


-=[ RAP: 287,421 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 12:49 PM
If you want to see what exactly I'm working on, you may here:
https://www.roblox.com/games/407343143/Weapon-testing


-=[ RAP: 287,356 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
DurstAuric is not online. DurstAuric
Joined: 12 May 2009
Total Posts: 8066
01 May 2016 04:17 PM
Aaah, it has been a while, anyone else know?


-=[ RAP: 286,863 || DurstAuric; the narb of ROBLOX ]=-
Report Abuse
Yamno is not online. Yamno
Joined: 10 Jun 2009
Total Posts: 123
01 May 2016 04:52 PM
How do you want the beam to be arranged?

Assuming that you want it to have the same direction as the Ray:

local Ray = Ray.new(Main.LaserShooter.CFrame.p, (Main.Mouse.Hit.p - Main.LaserShooter.CFrame.lookVector).unit * 300)
local Part, Position = game.Workspace:FindPartOnRay(Ray, Main.Player.Character, false, true)
local Distance = (Main.LaserShooter.CFrame.p - Position).magnitude
local Beam1 = Instance.new("Part", game.Workspace)
local Beam2 = Instance.new("Part", game.Workspace)
--... omitted because too long

Beam1.Size, Beam2.Size = Vector3.new(0.5, Distance, 0.3), Vector3.new(0.5, Distance, 0.5)

-- The math would like like this

--stuff put in temporary variables to make understanding easier
local origin = Main.LaserShooter.CFrame.p
local target = Position
local Distance = (target - origin).magnitude

local direction = ray.Unit --lookVector of ray, can also use ray.Direction. should change the variable name "Ray" to something else like "target_ray"
local position1, position2 = origin + direction * Distance / 2, origin + direction * Distance / 2

--Create a CFrame with a starting position and looking at a point (position + lookvector so it will also be looking in the direction of the lookvector)
Beam1.CFrame, Beam2.CFrame = CFrame.new(position1, position1 + direction), CFrame.new(position1, position1 + direction)

--Create a CFrame with a starting position and rotate to LookVector
local lookVector_CF = CFrame.new(Vector3.new(), direction)
local pos_CF = CFrame.new(position1)
Beam1.CFrame = pos_CF * lookVector_CF
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