Modding Help (Solved) Y-component of aim for melee ability

Discussion in 'Starbound Modding' started by lerdarim, Nov 4, 2019.

  1. lerdarim

    lerdarim Void-Bound Voyager

    Hello once again. Is it possible to retrieve Y-component of direction from mcontroller to aim (cursor) for melee weapons? Afaik melee weapons have no "aim" and thus they use only motion direction (left/right). But i suppose cursor coordinates or even relative position from player to it should be accessible from any script, yet i fail to find any function related to cursors.
     
  2. lerdarim

    lerdarim Void-Bound Voyager

    After quite a research i found out that weapon.lua contains updateAim() function with activeItem.aimAngleAndDirection(self.aimOffset, activeItem.ownerAimPosition()), which essentially does what i need. Or aimAngle, which returns angle solely, whether aimAngleAndDirection returns a list of two values, with direction as second one. However, i'm kinda dumb around getting this function used in my own script, since i dunno how to call "activeItem" from, well, script of that active item... Anyway, got stroke by much simpler decision to just allow rotation in stances animation config. Works like a charm. With one. freakin. exception. After the ability finishes, rotation does not go back to normal, player has to change into some other slot and back to restore normal angle. My first good idea was to restrict rotation on last stance, which essentially is a wait delay, but that didn't do since animation rotation seems to be relative, not absolute. I've read into animator functions, but the rotation functions work through transformation or rotation groups. And rotation groups are obsolete, said documentation. I've met somewhere in the code a transformation group called "weapon" and thought it's a default transformation group. Tried changing its rotation, tried resetting it - not exactly working...
    Although maybe tr.group "hand" would work since it's not the weapon but hand that rotates. Sadly got hit by this just now, gotta try that.
     
  3. Zaakari

    Zaakari Zero Gravity Genie

    That's quite the little wall of text there. Might I recommend paragraphs? :nuruwink:

    The "actitveItem" functions should be usable within your weapon ability's Lua file. You can see a list of functions on Starbounder.
    I think using those functions should be relatively straight-forward. But what issues did you run into?
    Right, the parameters for "activeItem.aimAngle" are confusing.
    Have you tried:
    Code:
    self.aimAngle = activeItem.aimAngle(config.getParameter("muzzleOffset") or {0,0}, activeItem.ownerAimPosition())
     
    Last edited: Nov 7, 2019
  4. lerdarim

    lerdarim Void-Bound Voyager

    I'm at risk of killing another savefile with that. I've tried adding a ranged ability to melee weapon (i know it's stupid but wanted to see what happens :D), resulted in some error about "muzzle" variable missing. Since "muzzle" usually is a part of a gun, i thought it's because of melee weapon. Tried making it melee, deleting that ability, quite a few things - couldn't restore it. That's why i doubt that melee weapons even have an aim angle (except for spears etc.), and that is why i tried to calculate it in ability script by myself.

    Functions ARE straightforward, you're right, and being somewhat a programmer myself i'm kinda familiar with coding, but what confuses me is the relation of objects. Y'see, weapon.lua has all the calculations of angle and direction. However, game abilties never call them directly, they just call updateAim() function cuz the weapons that use it are rotatable. I've tried quite a few different calculations (a week ago) but achieved nothing. Now i at least know though that activeItem. can be called from ability script.

    Simply put, all i needed was a traildash which is not tied to ground :D But most melee weapons don't rotate, they only have facing direction (left-right). So i was trying to calculate the angle towards cursor through difference in coordinates between entity (player) and the cursor. Which, as i think of it now, would not be entirely correct, but aanyway. I've found out a much simplier solution, i simply allowed rotation in "windup" stance, which lets you rotate it like gun/spear, and thanks to that updateAim() call works perfectly and i can dash in any direction. However. Because normally my weapon does not allow rotation (and right now none of the stances except for windup allow it too), it gets stuck in weird angles, for example, if you dash vertically downwards, your weapon will get stuck looking into the ground and your primary attacks will cut and poke dirt below you :D It is cured by switching onto another activeslot and back, but i'd like to fix it.
    So i'm now trying to reset rotation, but:
    1. transformation group rotation either renders weapon inoperable (prolly breaks the script) or does nothing.
    2. Today stumbled across activeItem.setArmAngle(0) in updateAim() function in weapon.lua, but sadly it doesn't help too.
     
  5. lerdarim

    lerdarim Void-Bound Voyager

    Uff, approached the problem again, solution turned out to be stupidly simple. I had to reset self.weapon.aimAngle via self.weapon.aimAngle = 0 and that was it...
     
  6. Zaakari

    Zaakari Zero Gravity Genie

    It's interesting how often coding problems seem to be the result of small errors, eh?
    (small, exceedingly difficult to find errors :nuruwink:)
     
  7. lerdarim

    lerdarim Void-Bound Voyager

    I've got used to those situations over the years.
    But that i can't call an error, more like lack of understanding how game or lua works)
     

Share This Page