Lua raycast ability

Discussion in 'Ideas and Suggestions' started by Dummiesman, Jan 6, 2015.

  1. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,699
    Hey! My suggestion is to allow raycasting in Lua. To implement , for example, self-driving vehicles ;).

    I think a good usage would be:
    Code:
    physics.raycast(float3 origin,float3 direction,long layermask = 0xFFFFFFFF, float distance = 1) returns a reference to the object in T3D or if it didn't hit, returns nil.
    --and
    physics.linecast(float3 origin,float3 end,long layermask = 0xFFFFFFFF) returns a table with hit info or nil
    
     
    #1 Dummiesman, Jan 6, 2015
    Last edited by a moderator: Jan 7, 2015
  2. CarlosAir

    CarlosAir
    Expand Collapse

    Joined:
    Nov 16, 2013
    Messages:
    336
    Could you explain in a noob understandable way what raycast is, and what does it provide? Like, I don't have the slightest idea of what you are talking about. :p

    Looks interesting, thanks.
     
  3. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,699
    Raycast casts a ray in the specified direction at a certain length. If it hits an object it would return the info of the object, and if it never hits anything it would return nil.
    Linecast is a version of raycast where instead of a direction and length , you only pass in 2 point parameters and it raycasts between the 2.
     
  4. 14ramosr

    14ramosr
    Expand Collapse

    Joined:
    Sep 7, 2013
    Messages:
    979
    Quick question: what would this be useful for? (not being a smartass, just genuinely curious)
     
  5. SixSixSevenSeven

    SixSixSevenSeven
    Expand Collapse

    Joined:
    Sep 13, 2013
    Messages:
    6,958
    adaptive inverse kinematics for a walker. AI. Altitude above ground level. Other shit.
     
  6. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,699
    Vehicle AI.

    if(physics.raycast(obj:getPosition(),{0,1,0},1) then
    --Vehicle collision imminent. Stop!
    end
     
  7. Aboroath

    Aboroath
    Expand Collapse

    Joined:
    Aug 25, 2013
    Messages:
    3,804
    Dynamic altimeter perhaps, for aircraft? Radar guns? night vision? Sounds like a software "radar" to me.
     
  8. 14ramosr

    14ramosr
    Expand Collapse

    Joined:
    Sep 7, 2013
    Messages:
    979
    I like this idea... Devs! make it a thing!
     
  9. SixSixSevenSeven

    SixSixSevenSeven
    Expand Collapse

    Joined:
    Sep 13, 2013
    Messages:
    6,958
    most shooters use raycasts for hit detection too
     
  10. 14ramosr

    14ramosr
    Expand Collapse

    Joined:
    Sep 7, 2013
    Messages:
    979
    I wouldnt say most (im assuming youre talking about hitscan) Maybe games like CoD and TF2 use it, but more "realistic" games like battlefield (the more recent ones), Arma etc use much more complicated ways of detecting a hit.
     
  11. SixSixSevenSeven

    SixSixSevenSeven
    Expand Collapse

    Joined:
    Sep 13, 2013
    Messages:
    6,958
    Hitscan is simply a raycast.
    Generally you find few shooters bother with true projectile simulation, its more CPU demanding for what is usually little gain. Bullet penetration through a surface and bouncing don't require projectile simulation, that can actually be done by creating a new raycast from the landing point of the first ray.
    ARMA does use full projectile even going as far as considering the recoil of the firearm against the soldier and how that would alter the bullet leaving the barrel. Battlefield and halo are both notable for being a hybrid. The source engine supports both but for most weapons uses hitscans (half life 2 crossbow is an example of being a genuine projectile). The weirdest one is fallout, hitscans all round *unless* the game decides its going to be a critical hit in which case its projectile, there are mods to switch it to full projectile.
     
  12. Dummiesman

    Dummiesman
    Expand Collapse

    Joined:
    Sep 17, 2013
    Messages:
    4,699
    There are several ways shooters look for projectile hits, here are 3 examples.

    1) Actually physically simulating the projectile, weight, etc affects it. Ideal for tank projectiles, mortar projectiles, etc that would need a visual as well. Requires the most CPU use, and faster physics timesteps. Inefficient for small projectiles that would come out of an SMG or similar.

    2) Faking physics. Shooters with only light weaponry such as pistols and light machine guns will use a method like this. It will, upon firing, check if it is going to hit anything. If it hits anything then it will send a "message" to that object saying it has been hit

    3) A light simulation of the projectile. Only distance and direction are simulated. This way allows for sound and visual simulation, and is much lighter on the CPU as well.
     
  13. Nadeox1

    Nadeox1
    Expand Collapse
    Spinning Cube
    BeamNG Team

    Joined:
    Aug 5, 2012
    Messages:
    14,697
    I believe the vehicle would be able to "analyze" the surroundings.

    Ex. AI controlled car would be able to avoid obstacles (I believe) (or even follow and enclosed track, i believe still).
     
  14. logoster

    logoster
    Expand Collapse

    Joined:
    Sep 5, 2012
    Messages:
    2,084

    i agree with this statement
     
  15. Nikitaman369

    Nikitaman369
    Expand Collapse

    Joined:
    Jan 16, 2014
    Messages:
    68
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice