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: Ray Casting Issues

Previous Thread :: Next Thread 
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
14 Apr 2016 06:02 PM
Hello all,

I am having issues with this ray based projectile system I am writing. The ray version of the arc is all messed up, but when I draw the ark, it looks completely fine. I am lost here, any ideas?

Thanks,

Ion.

Here is the code.
--[[This function generates a y offset based on the distance from the start point (x)]]--
function _G.Ballistic:GetVerticle(x)
local p1 = -((196.2 * (1/math.cos(self.Delta))^2)/(2*self.Velocity^2))*x^2
local p2 = x*math.tan(self.Delta)
return p1 + p2
end
--[[This function creates rays and stores them in a table. I think this is where the problem is.]]--
function _G.Ballistic:Calculate (h, stop)
self.Rays = {}
local lvU = self.LookVector.Unit
local lastPos = self.Start
for i=0, stop do
local dir = self.Start + (lvU * (h) + Vector3.new(0, self:GetVerticle(i*h),0))
local r = Ray.new(lastPos, dir)
local h, p, n, m = game.Workspace:FindPartOnRayWithIgnoreList(r, self.IgnoreTable)
table.insert(self.Rays, r)
lastPos = dir
if h ~= nil then
return h, i, p, n, m
end
end
end
--[[This function displays the arc. When this is called, the parts act as they are supposed to.]]--
function _G.Ballistic:Display (caliber, length)
local cal = caliber or 0.3
self.Parts = {}
local l = length or #self.Rays
for i=1, #self.Rays do
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Bright red")
beam.FormFactor = "Custom"
beam.Material = "Neon"
beam.Transparency = 0.25
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
beam.Name = tostring(i)
local distance = (self.Rays[i].Origin - self.Rays[i].Direction).magnitude
beam.Size = Vector3.new(cal, cal, distance)
beam.CFrame = CFrame.new(self.Rays[i].Origin, self.Rays[i].Direction) * CFrame.new(0, 0, -distance / 2)
table.insert(self.Parts, beam)
end
end
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
14 Apr 2016 08:50 PM
Bump.
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
14 Apr 2016 10:13 PM
Bump. Any Ideas? I do not need code, just tell me where my logic went wrong, and how I should fix it.

Thanks,

Ion
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
17 Apr 2016 09:59 PM
Bump. Any ideas?
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 10:27 AM
Bump. Anybody? Here is what I believe the problematic code is:

--[[This function generates a y offset based on the distance from the start point (x)]]--
function _G.Ballistic:GetVerticle(x)
local p1 = -((196.2 * (1/math.cos(self.Delta))^2)/(2*self.Velocity^2))*x^2
local p2 = x*math.tan(self.Delta)
return p1 + p2
end
--[[This function creates rays and stores them in a table. I think this is where the problem is.]]--
function _G.Ballistic:Calculate (h, stop)
self.Rays = {}
local lvU = self.LookVector.Unit
local lastPos = self.Start
for i=0, stop do
local dir = self.Start + (lvU * (h) + Vector3.new(0, self:GetVerticle(i*h),0))
local r = Ray.new(lastPos, dir)
local h, p, n, m = game.Workspace:FindPartOnRayWithIgnoreList(r, self.IgnoreTable)
table.insert(self.Rays, r)
lastPos = dir
if h ~= nil then
return h, i, p, n, m
end
end
end
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 11:56 AM
Bump, again.
Report Abuse
AbstractMadness is not online. AbstractMadness
Joined: 22 Dec 2014
Total Posts: 20425
18 Apr 2016 11:56 AM
what kind of math is this? i wanna learn



#code R+ | local RAP = "R$77,885"; local robux = "R$5,723"
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 12:29 PM
I am using some elements of calculus. Namely the property of local linearization. This essentially means that if you look at a small enough section of a curve, it is effectively a straight line. That is what I am trying to get my code to do. It takes a curve and breaks it down into linear segments. I am also using a little bit of derivation.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
18 Apr 2016 12:37 PM
Are you trying to preserve the rotation of where this started? Adding a Vector3 to another Vector3 moves in the global space rather than by reference/object space.
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 12:45 PM
Yes, I am. This is for a tank that rotates the turret and elevates the gun. How do I compensate for this?
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
18 Apr 2016 12:47 PM
What is self.Start?
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 01:03 PM
Ok, I guess I forgot to explain some things. self.Start is the position the arc originates from. self.LookVector is the direction the arc should go. self.Delta is the angle of elevation of the cannon. self.Velocity is the starting velocity of the projectile to be simulated, or V0.
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 02:06 PM
Bump. Any ideas?
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 03:26 PM
Bump. Any suggestions are greatly appreciated.
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 04:21 PM
Bump
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
18 Apr 2016 04:30 PM
I haven't read your entire code because I'm lazy. That being said:

local lastPos = self.Start
local dir = self.Start + (lvU * (h) + Vector3.new(0, self:GetVerticle(i*h),0))
local r = Ray.new(lastPos, dir)

The second Ray parameter (dir in this case) should be a direction relative to the lastPos. I'm not sure what value some of your variables will take on (h) but assume this is not the case.

Report Abuse
Dr_Doge is not online. Dr_Doge
Joined: 07 Dec 2011
Total Posts: 645
18 Apr 2016 04:37 PM
I'm a Programer and everything, but Woh that's a lot of math....
Are you making some sort of Custom Global Ray Functions thing, or is this just for a single project?

Can I see this after your done?

PS if you want more help, Google "Roblox Script Helpers"

They have a website just for helping programmers on roblox help other programmers on roblox....
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
18 Apr 2016 04:39 PM
You're essentially calling:

Ray.new(startPos, endPos)

when it should be:

Ray.new(startPos, vel)


Following would cast 1 stud downward from startPos.

Ray.new(startPos, Vector3.new(0, -1, 0))
Report Abuse
darthpyro is not online. darthpyro
Joined: 18 Aug 2009
Total Posts: 3569
18 Apr 2016 04:44 PM
Try this:

local dir = (lvU * (h) + Vector3.new(0, self:GetVerticle(i*h),0)) -- removed self.Start... should just be the velocity with a vertical adjustment?

and then visualize it like so:

local distance = self.Rays[i].Direction.magnitude
beam.CFrame = CFrame.new(self.Rays[i].Origin, self.Rays[i].Origin + self.Rays[i].Direction) * CFrame.new(0, 0, -distance / 2)
Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 05:07 PM
At Dr_Doge, I am trying to make a semi custom ray casting thing that raycasts the path a projectile would take in a vacuum (No Drag).

At DarthPyro: That makes sense. I will give it a try. Thank you so much!

Report Abuse
iondriver is not online. iondriver
Joined: 18 Nov 2012
Total Posts: 757
18 Apr 2016 05:24 PM
Ok, I am almost there. Thanks Darthpyro, the rays now appear to match the parts. The next issue is this https://gyazo.com/87976c77f4afdad4f3a87d359723f5b6 <<-- I hope that the link didn't get filtered. Anyway, the projectiles arc upwards infinitely. I think I can solve this problem though. I will post again if I can't. Thanks for all of the responses!
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