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
 

RayCast in GUIs

Previous Thread :: Next Thread 
makerror is not online. makerror
Joined: 29 Aug 2011
Total Posts: 493
10 Jan 2014 08:11 AM
I already made GUI collision detection and response. Right now I need to make similar ray like roblox have. Just need to change brick to GUI frames and 3D to 2D.
Any ideas how to do it? I can just run loop and check if bullet is inside frame, but I don't think script performance going to be good.
Report Abuse
Decompiler is not online. Decompiler
Joined: 30 Aug 2012
Total Posts: 1453
10 Jan 2014 09:17 AM
Checking if a bullet is inside a frame is a terrible way to do it. What if the speed that the bullet is going is faster than the frame?

You could try finding the equation of the bullet's trajectory and the equations of the sides of the frame. If the bullet's trajectory and one of the frame's equations match then you have a hit.
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
10 Jan 2014 09:29 AM
Wikipedia "Ray casting"

Google "Ray casting algorithm"


???

Report Abuse
su8 is not online. su8
Joined: 06 Mar 2009
Total Posts: 6334
10 Jan 2014 10:25 AM
you probably want line-line intersection

http://en.wikipedia.org/wiki/Line-line_intersection
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
10 Jan 2014 10:42 AM
omg its su8!!!!!!!!
Report Abuse
Oysi is not online. Oysi
Joined: 06 Jul 2009
Total Posts: 9058
10 Jan 2014 11:19 AM
Here's a function I made some time ago:

function lineIntersection(p, r, q, s)
  local t = (s.x*(p.y - q.y) - s.y*(p.x - q.x)) / (r.x*s.y - s.x*r.y)
--  local u = (r.x*(p.y - q.y) - r.y*(p.x - q.x)) / (r.x*s.y - s.x*r.y)

  if t >= 0 and t <= 1 then
    return p + r*t
  end
end

Which is based on this:

  p + t r = q + u s

  t = (q - p) × s / (r × s)
  u = (q - p) × r / (r × s)

And it works much like Roblox's 3D raycasting, in that a line segment is a position and an offset from that position. You give it positionA, offsetA, positionB, offsetB. So if you do, for example:

lineIntersection(
Vector2.new(0, 0), Vector2.new(0, 10), -- from (0, 0) to (0, 10)
Vector2.new(5, 5), Vector2.new(-10, 0) -- from (5, 5) to (-5, 5)
)

Then it should yield (0, 5).
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
10 Jan 2014 11:23 AM
...Oysi, whats with "p + t r"? Is that "p + t * r"?
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