Modding Help How to make projectile fire based on way you're looking?

Discussion in 'Starbound Modding' started by ImHereForTheMods, Mar 1, 2017.

  1. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    As the title says.
    I've tried "flippable" : true, but that doesn't seem to have done it.
    Maybe missed it somewhere though, dunno.

    I'll look into it, but I usually find it once I make a post like this... hah.
     
    Last edited: Mar 1, 2017
  2. IHart

    IHart Scruffy Nerf-Herder

    I've never seen this not be the case. Share the file you are working on?
     
  3. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Sure, I'll link it right as soon as I get to my computer again.
     
  4. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Here y'are, maybe you can figure it out.
    I'm sorta stuck.
     

    Attached Files:

  5. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Oh yeah, should have mentioned, this problem is with the human tier 1-2 staff, apex tier 1-2 staff and the glitch tier 2 staff, that probably would've been useful to know.
     
  6. IHart

    IHart Scruffy Nerf-Herder

    you just want it to fire straight? not follow the cursor like the other staves?
     
  7. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Yep, pretty much.
     
  8. IHart

    IHart Scruffy Nerf-Herder

    havent figured it out yet, am still tinkering
     
  9. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Aight, that's fine. Thank you for the help so far.
     
  10. bk3k

    bk3k Oxygen Tank

    Call this a decent guess. I haven't tested it. Things could be backwards(270 instead of 90) etc.

    Lets look at weapon.lua
    line 124
    Code:
    local aimAngle, aimDirection = activeItem.aimAngleAndDirection(self.aimOffset, activeItem.ownerAimPosition())
    That isn't apparently what you want.

    So suppose I gave you this function
    Code:
    facing_aimAngleAndDirection = function(t1, t2)
      if ((t1[1] - t2[1]) < 0) then
        return 90, -1
      else
        return 90, 1
      end
    end
    You might call it like this
    Code:
    local aimAngle, aimDirection = facing_aimAngleAndDirection(mcontroller.position(), activeItem.ownerAimPosition())
    Perhaps that will get you somewhere. I replacing that bit of code would have a weapon that fires straight ahead. It is possible that I misunderstand your intent though.
    edit: easier way. I forgot about mcontroller.facingDirection()
     
    Last edited: Mar 8, 2017
  11. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Thanks for the info! Unfortunately I'm not all that experience paced with Lua, so I wouldn't know what to do with that code...
    How would I go about using mcontroller.facingDirection though?
    Thanks again!
     
  12. MetaFace

    MetaFace Guest

    mcontroller.facingDirection(), you only have to put that in, facingDirection() takes no arguments, it however outputs a 1 if facing the right and a -1 if looking left. This is usually used to tell the game which direction some projectile should go. If you need anything else I can check it, plus I've been reading all these over for awhile.
     
  13. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Thanks for that info! However, I still don't know what to do with that code...
    Does it go in the .activeitem file or the lua? And if in the lua... where / how?
    Thanks in advance!
     
  14. MetaFace

    MetaFace Guest

    In the lua, usually used as a multiplier (against projectile velocity) to tell which direction to go. Like "projectileVelocity * mcontroller.facingDirection" as a terrible example.
     
  15. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Okay, but, where about sin the lua? At the bottom? Or a certain place?
    And, weapon.lua? Or some other?

    Thanks again.
     
  16. MetaFace

    MetaFace Guest

    I'm gonna need a reference, I'm on my phone so I can't really say, I understand what your sayin now, I'll be back tomorrow with a proper answer unless someone else does first, then in that case... Rood.
     
  17. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    Aight, well, thanks again.
    Heh.
     
  18. MetaFace

    MetaFace Guest

    So in staffs (function ControlProjectile:createProjectiles())
    Code:
    local fireDirection = world.distance(aimPosition, self:focusPosition())[1] > 0 and 1 or -1

    But you're looking for a straight firing staff? Then in gunfire.lua you'll see

    Code:
    function GunFire:aimVector(inaccuracy)
      local aimVector = vec2.rotate({1, 0}, self.weapon.aimAngle + sb.nrand(inaccuracy, 0))
      aimVector[1] = aimVector[1] * mcontroller.facingDirection()
      return aimVector
    end
    This is the part that tells the bullet to move in the direction that you're aiming, if that's not enough then you can read into the whole gunfire.lua file
     
  19. ImHereForTheMods

    ImHereForTheMods Cosmic Narwhal

    So, if I am not mistaken, in the staff lua, I'd see that code, and I'd replace it with the code you gave from the gunfire lua?
    Or...?
    Thanks again!
     
  20. MetaFace

    MetaFace Guest

    If you are looking to make the staff fire in a straight line, then yeah, use the gunfire lua in the staff's lua code, you may need to do a lot of tweaking to get it to work right.
     

Share This Page