Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: Trivial Psychic on November 28, 2016, 06:22:26 pm

Title: Request: Jettison-Cargo w/Speed
Post by: Trivial Psychic on November 28, 2016, 06:22:26 pm
I've got a situation with one of my loop missions in FS1: Enhanced (http://www.hard-light.net/forums/index.php?topic=92783.0), where Shivan freighters fully loaded with cargo are to release the cargo quickly and depart.  I was hoping to use the jettison-cargo-delay sexp, but it simply releases the cargo and it gets scraped on the hull.  Is there any easy way to either modify the existing sexp or generating a new one with user-definable ejection speed so they can clear the ship?
Title: Re: Request: Jettison-Cargo w/Speed
Post by: 0rph3u5 on November 29, 2016, 05:06:58 am
Not to cut of the feature request, but can't you achieve what you are looking for with high blast, no damage explosion-effects? (You would have to set the freighters to immobile for second or two, so they don't get tossed around)
Title: Re: Request: Jettison-Cargo w/Speed
Post by: The E on November 29, 2016, 05:17:03 am
I've got a situation with one of my loop missions in FS1: Enhanced (http://www.hard-light.net/forums/index.php?topic=92783.0), where Shivan freighters fully loaded with cargo are to release the cargo quickly and depart.  I was hoping to use the jettison-cargo-delay sexp, but it simply releases the cargo and it gets scraped on the hull.  Is there any easy way to either modify the existing sexp or generating a new one with user-definable ejection speed so they can clear the ship?

Well, it would have to be ejection vector and speed, but yes, this is certainly doable.
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Trivial Psychic on November 29, 2016, 06:41:13 pm
I felt that the vector should be down the dockpoint normals.  The speed, I felt, would need to be user-definable, because some ships would only need a slight kick, while others like the Chronos would need a more significant ejection speed to clear the hull.
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Mito [PL] on November 30, 2016, 12:25:44 pm
How about set-object-speed and collision groups?
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Goober5000 on December 02, 2016, 11:10:42 pm
Here is the code in question:

Code: [Select]
// physics stuff
vm_vec_sub(&pos, &cargo_objp->pos, &objp->pos);
impulse = pos;
vm_vec_scale(&impulse, 100.0f);
vm_vec_normalize(&pos);

// whack the ship
physics_apply_whack(&impulse, &pos, &cargo_objp->phys_info, &cargo_objp->orient, cargo_objp->phys_info.mass);

That vector is wrong; what it's doing is comparing the centers of the two ships.  It should use the dockpoint normal as Trivial Psychic says.  This explains why some cargo containers get hung up on their ships.

Furthermore, since not all dockpoints are equally distant from the centers of their host ships, the farther dockpoints will be ejected with greater force than the closer dockpoints.

The best solution is probably to write a new jettison-cargo sexp and deprecate the old one.  The new sexp should use proper physics and provide an optional argument for ejection force.  I should be able to do that tomorrow.
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Trivial Psychic on December 03, 2016, 06:53:03 am
Awesome.  Thanks.  Perhaps instead it could be called eject-cargo.
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Goober5000 on December 04, 2016, 08:40:06 pm
PR posted:
https://github.com/scp-fs2open/fs2open.github.com/pull/1085
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Trivial Psychic on December 05, 2016, 12:55:19 am
Awesome!  Thanks!  :yes:
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Trivial Psychic on December 11, 2016, 11:58:33 am
Seems to be working fine.  Thanks again!  :yes:
Title: Re: Request: Jettison-Cargo w/Speed
Post by: Goober5000 on December 11, 2016, 03:29:10 pm
Glad to hear it. :)