Author Topic: Create Weapon at Relative Coordinates  (Read 1586 times)

0 Members and 1 Guest are viewing this topic.

Offline SF-Junky

  • 29
  • Bread can mold, what can you do?
Create Weapon at Relative Coordinates
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:

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Create Weapon at Relative Coordinates
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.

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Create Weapon at Relative Coordinates
The BP2 mission 'Post Meridian' has an example of this at work.

 

Offline Rhymes

  • Galactic Mediator
  • 29
  • Fatum Iustum Stultorum
Re: Create Weapon at Relative Coordinates
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.
If you don't have Knossos, you need it.

“There was a button," Holden said. "I pushed it."
"Jesus Christ. That really is how you go through life, isn't it?”

 
Re: Create Weapon at Relative Coordinates
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.

 
Re: Create Weapon at Relative Coordinates
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" )
   )

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Create Weapon at Relative Coordinates
Nah you can set it to use relative coordinates iirc.

 
Re: Create Weapon at Relative Coordinates
Really? Where? I'm asking cause I'm really tired of entering the same numbers 3 times in a row.

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: Create Weapon at Relative Coordinates
No ignore me your way is better. I think. I’d have to check a mission.

 
 
Re: Create Weapon at Relative Coordinates
: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.

 

Offline SF-Junky

  • 29
  • Bread can mold, what can you do?
Re: Create Weapon at Relative Coordinates
You need those extra arguments for proper positioning.
: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).
« Last Edit: December 17, 2019, 02:58:59 pm by SF-Junky »

 

Offline JSRNerdo

  • [`_`]/
  • 29
  • Gone!
Re: Create Weapon at Relative Coordinates
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.
Former Inferno lead, BTA fredder-ish and DE fredder. Driven out by ordinary fascists the_e, aesaar and general battuta. Will return if they're ever removed.

 

Offline SF-Junky

  • 29
  • Bread can mold, what can you do?
Re: Create Weapon at Relative Coordinates
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.