Hard Light Productions Forums

Modding, Mission Design, and Coding => The FRED Workshop => Topic started by: SF-Junky on December 16, 2019, 02:49:11 pm

Title: Create Weapon at Relative Coordinates
Post by: SF-Junky on December 16, 2019, 02:49:11 pm
I've played around with this for hours now and I'm intellectually overwhelmed completely.

What I want to do in the end is to simulate a ship fire secondary weapons via the weapons-create SEXP. So I need those weapons to appear at coordinates relative to the ship's axes.

Maybe we can start with something easy. How can I make a weapon (e.g. Trebuchet) to appear 100 meters in front of the players ship, no matter where Alpha 1 is actually located in the field of battle and no matter where it is headed?

Maybe this is easy. Maybe this is difficult. Maybe this is not possible. Whatever it is, my brain is about to explode over this. :nervous:
Title: Re: Create Weapon at Relative Coordinates
Post by: General Battuta on December 16, 2019, 02:53:32 pm
Oh it's easy! If nobody else has explained it shortly I'll do an effort post. It's still technically my work day so I should get back to work.

You basically just use weapon-create, then, in the coordinate fields in that SEXP, replace the raw numbers with + operators. Then, inside those plus operators, use get-object-X/Y/Z and an offset value.

Does that make any sense?

Weapon-create
    (weapon details)
    +
        (get-object-x)
        (some value)
    +
        (get-object-y)
        (some value)
    +
        (get-object-z)
        (some value)

You can replace get-object-XYZ with get-subsystem-XYZ to fire from turrets.
Title: Re: Create Weapon at Relative Coordinates
Post by: General Battuta on December 16, 2019, 02:53:58 pm
The BP2 mission 'Post Meridian' has an example of this at work.
Title: Re: Create Weapon at Relative Coordinates
Post by: Rhymes on December 16, 2019, 03:34:57 pm
Inferno Nostos has something similar in mission 7 (The Gates of Babylon). We use it to simulate wingmates targeting subsystems because, as it stands, the AI is really not very good at that. We call it ai-pretend-to-bomb.
Title: Re: Create Weapon at Relative Coordinates
Post by: Nightmare on December 16, 2019, 03:42:16 pm
It should be noted that relative coordinates are a bit tricky as the way Battuta depicted it the coordinates will be relative to the world grid, not the ship.
Title: Re: Create Weapon at Relative Coordinates
Post by: Nightmare on December 16, 2019, 03:50:02 pm
Here's an example

Code: [Select]
   ( weapon-create
      "<none>"
      "Weapon"
      ( get-object-x
         "Fighter"
         "<none>"
         100
         100
         425
      )
      ( get-object-y
         "Fighter"
         "<none>"
         100
         100
         425
      )
      ( get-object-z
         "Fighter"
         "<none>"
         100
         100
         425
      )
      ( get-object-pitch "Fighter" )
      ( get-object-bank "Fighter" )
      ( get-object-heading "Fighter" )
   )
Title: Re: Create Weapon at Relative Coordinates
Post by: General Battuta on December 16, 2019, 04:18:32 pm
Nah you can set it to use relative coordinates iirc.
Title: Re: Create Weapon at Relative Coordinates
Post by: Nightmare on December 16, 2019, 04:40:59 pm
Really? Where? I'm asking cause I'm really tired of entering the same numbers 3 times in a row.
Title: Re: Create Weapon at Relative Coordinates
Post by: General Battuta on December 16, 2019, 05:45:00 pm
No ignore me your way is better. I think. I’d have to check a mission.
Title: Re: Create Weapon at Relative Coordinates
Post by: Axem on December 16, 2019, 05:48:22 pm
You need those extra arguments for proper positioning. (https://wiki.hard-light.net/index.php/Tutorial_-_In-Mission_Jumps#warp-effect_and_Relative_Coordinates)
Title: Re: Create Weapon at Relative Coordinates
Post by: Nightmare on December 16, 2019, 06:14:57 pm
:sigh: I think this relative coordinate stuff is one of the edgiest points in FRED; unless you explicetely know about it there's basically no way you can figure it out yourself without loosing all nerves on the way.
Title: Re: Create Weapon at Relative Coordinates
Post by: SF-Junky on December 17, 2019, 02:49:03 pm
You need those extra arguments for proper positioning. (https://wiki.hard-light.net/index.php/Tutorial_-_In-Mission_Jumps#warp-effect_and_Relative_Coordinates)
:banghead: :banghead: :banghead: :banghead:

Yeah, if you use SEXPs properly they do what you want. Totally did not see those extra arguments are available.

Well, launching from turret coordinates is fairly easy, then. Now I have the next problem, though. I want the missile to fly in the right direction.

What I want to achieve is that the missiles launch vertically from their turret. So if the turret is on the top of the ship I want it to head "upwards", for turrets on the ventral side I want missiles to head "downwards" and for turrets and starboard and port to head, guess what, to starboard and port, respectively.

I started with just the pitch, i.e. rotation around the x-axis. It's value is never bigger than 90 degrees. Instead of increasing above +90 or decreasing below -90 degrees, bank and heading switch from 0 to 180 degrees and the value of pitch starts to shrink again.

€: ... which perfectly makes sense. Because if you rotate an object by +100 degrees around it's x-axis that is like turning it around the y-axis by 180 degrees and turning around +80 degrees around the x-axis. Right?

So if I use the get-object-pitch +270 degrees argument, than it works as long as bank and heading are 0. But as soon as the ship banks too far and bank and heading switch to 180, the missile goes into the wrong direction ("downward" instead of "upward").

Here is my event:

Code: [Select]
$Formula: ( when
   ( key-pressed "1" )
   ( weapon-create
      "XXX"
      "AreaBomb"
      ( get-object-x "XXX" "turret01" )
      ( get-object-y "XXX" "turret01" )
      ( get-object-z "XXX" "turret01" )
      ( + 270 ( get-object-pitch "XXX" ) )
      ( + 0 ( get-object-bank "XXX" ) )
      ( + 0 ( get-object-heading "XXX" ) )
      "GTC Leviathan 1"
   )
)
+Name: Event name
+Repeat Count: 5
+Interval: 2

turret01 is located on the top side of XXX (which is a Satis).
Title: Re: Create Weapon at Relative Coordinates
Post by: JSRNerdo on December 17, 2019, 03:40:12 pm
I recommend you use a dummy ship with dynamic waypoints, say a stealthed cloaked nocollide invisible myrm that doesn't move and has all the protection flags on. Set its position to that of the turret and then put a waypoint say, 500m above it relative to it, and then set-ship-facing-object the ship to the waypoint. Then you can use the dummy ship's orientation without having to worry about things. This is basically how Inferno does its pretend-to-fire-turret and pretend-to-bomb tricks.
Title: Re: Create Weapon at Relative Coordinates
Post by: SF-Junky on December 19, 2019, 01:58:32 pm
That did the trick. You don't need the waypoint, though, as you can simply use the set-object-facing SEXP with relative coordinates.

Thanks for your reply and help, also to the other respondents.