Modding Help Beam Weapons

Discussion in 'Starbound Modding' started by Heiixx, Dec 14, 2013.

  1. Heiixx

    Heiixx Space Hobo

    I've started working on a laser beam cannon and have hit some design snags.
    I have devised a couple ways to "workaround" the problem, but the end result will be far inferior in quality to something that has specific code written for it.

    Here's TL: DR...
    The current animation method will not work for a beam weapon hitting at different distances. i.e. ugly animation quality. Also, need a method for animating a weapon.

    Here's the long version...

    Currently the game's animation method suits projectiles that travel from point a to point b, but do not occupy the entire space between a and b simultaneously. i.e. bullets. For a beam weapon to work, it must fill in an entire area between a and b instantly. This makes one large projectile a possible workaround, however, the projectile will not fit properly at all distances. So I've thought of a solution, but it requires someone with a lot of coding experience in this language. Unfortunately I only know some C++ and Assembly, and cannot implement the functionality myself.

    Proposed method:

    1. Create an event loop that activates upon equipping a beam weapon to an active hand. (An event loop is same thing windows uses to determine things like mouse movement.)

    2. WIthin that loop continuously update the distance of the character to the cursor, and measure that distance in pixels.

    3. Also within the loop, constantly check for terrain between in path between the character and cursor.

    4. If there is terrain blocking the path, determine the pixel distance between the terrain and the character.

    5. If there is terrain in the way, set a variable to record that status, likewise unset it if there is no longer any obstruction.

    6. Split the projectile image into two files, a body and an end. The body would be a single column of pixels, and the body would be about five columns of pixels to draw the end of the beam.

    7. Upon firing, load the appropriate distance variable depending on the status of the beam path.

    8. Subtract 5 pixels from that distance for the beam end image, and fill in all the remaining pixels with the beam body image duplicated.

    8a. Would be nice to have animation possibilities in the end and body to allow for laser animation.

    9. Determine all creatures hit in that area and apply damage.

    10. Return to the event loop.

    These could simply be the ravings of an insane man, but I think this method will actually work to have good looking, functioning beam weapons.

    Hopefully someone knowledgeable can reply, or maybe something similar is being done the dev's already. Either way. until functionality like this exists, I don't think good looking beam weapons will be possible. But, I will still try to make a working version of my workaround idea to demonstrate the problem with the current animation system.
     
  2. Alphanos

    Alphanos Orbital Explorer

    Here's a possible partial alternative. Make the projectiles a little bit long, but mostly very fast-moving and with a very high rate of fire. This should allow you to get the tail end of one projectile meeting the front of the next. So you'd get most of the effects of a beam-style weapon.
     
    Cayote likes this.
  3. tifel100

    tifel100 Void-Bound Voyager

    If what I read from the only 5 lines I read, you want to have a projectile that isn't effected by gravity?
    If that's what you mean, I think you mean something similar to the brain extractor, you just make a hit box of how long you want it and stuff.
     
  4. Heiixx

    Heiixx Space Hobo

    The problem with that solution is that you end up with "segments" that are connected properly in the image, which ruins the effect of looking like a single beam. I'm trying hurry up and get this prototype one done so I can demonstrate the visual effect I'm going for.
     
  5. Platoonsgt1

    Platoonsgt1 Big Damn Hero

    I understand what you're trying to do fully, I've tried making this in Gamemaker many times before (and succeeded)

    I don't know that this is possible in Starbound at this current point, I agree that being able to crate a variable by raycasting for terrain (checking pixel by pixel the distance from source to collision point) would be a useful feature to use, but I see no feasible way to implement this.
     
  6. krail

    krail Void-Bound Voyager

    This kind of 'raycasting' or checking for block collisions between two points is possible in lua scripts - check out the code for the targeted blink tech.
     
  7. Tyler1456

    Tyler1456 Space Spelunker

    I really hope you figure out how to do this. Does anyone think that it's possible to make a laser pointer type of thing (think Dead Space http://www.relyonhorror.com/wp-content/uploads/2011/02/5-1024x576.png) for a gun or flashlight? I was thinking that I would probably have to create a flashlight with a really small radius, but I can't seem to get it down. Any ideas?
     
  8. Platoonsgt1

    Platoonsgt1 Big Damn Hero

    Hmm, should I try to make the projectile recursively spawn more projectiles until they hit a surface, or try to get the distance before firing, and then spawn appropriate projectiles to fill the space? I don't know if I can pull this off, but I'll try both if the first one fails.

    Edit: I can't seem to find any held items which activate a script, It's hard to determine what parameters I can use without something to refer too.

    Edit2: What do I use in place of tech.position() for a held item instead of a tech?
    Code:
      if doPathCheck then
        local collisionBlocks = world.collisionBlocksAlongLine(tech.position(), position, true, 1)
        if #collisionBlocks ~= 0 then
          local diff = world.distance(position, tech.position())
          diff[1] = diff[1] / math.abs(diff[1])
          diff[2] = diff[2] / math.abs(diff[2])
    
          position = {collisionBlocks[1][1] - diff[1], collisionBlocks[1][2] - diff[2]}
        end
      end
     
    Last edited: Dec 15, 2013
  9. Platoonsgt1

    Platoonsgt1 Big Damn Hero

    All I need is to be able to trigger this code using a held weapon/item. What's the data for energy usage and player location, and how do I trigger the code to run?
    Code:
    function beamRange(position)
    
      local collisionBlocks = world.collisionBlocksAlongLine(tech.position(), position, true, 1)
      if #collisionBlocks ~= 0 then
        local diff = world.distance(position, tech.position())
        diff[1] = diff[1] / math.abs(diff[1])
        diff[2] = diff[2] / math.abs(diff[2])
       
        position = {collisionBlocks[1][1] - diff[1], collisionBlocks[1][2] - diff[2]}
      end
     
      return position
    end
    
    function uninit()
      tech.setParentAppearance("normal")
    end
    
    function input(args)
      if args.moves["special"] == 1 then
        return "blink"
      end
    
      return nil
    end
    
    function update(args)
      local energyUsage = tech.parameter("energyUsage")
    
      if args.availableEnergy > energyUsage then
        local beamDist = nil
        beamDist = beamRange(args.aimPosition)
    
        if beamDist then
          -- Fire Laser
          return energyUsage
        else
          -- Make some kind of error noise
          return 0
        end
      end
    end
    

    Yes, I do know what to do for --Fire Laser, I'll be working on it while waiting for a response.
     

Share This Page