News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Re: How to compile Doom 3 source

Started by solarsplace, October 24, 2014, 09:52:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

solarsplace

Quote from: solarsplace on October 24, 2014, 08:02:51 AM
Hi

Finally had time to test this out properly and my findings agree with yours. The behaviour is different when the script is run from the state_killed event.

The answer to why this is happening and the solution took quite a bit of fiddling to find out. However, this is quite a good example of why it is often easier to do things like this from code within the SDK rather than scripts. However, at the same time, it is also a good example that where there is a will there is very frequently a way with scripts if that is how you want to work.

There are two reasons why the script does not work from within the state_killed event:

#1

The decal functionality of the FX requires that the FX origin is about 4 to 8 units from the floor. As we can see, the origin of the FX is further from the floor than this when spawned using the AI origin in this event.

#2

If the AI has a ragdoll, then because of the sequence of events in the SDK and the SDK setting the script "state_killed" and the transition into ragdoll state, then running "think" for the AI which updates the script... This means that from script in the state_killed event you are not getting the origin point of the MD5 model. You are getting the origin point based on the articulated figures "body" containing the "origin" joint in the articulated figure file. Look below and you can see the origin z offset. I have proved this is the case by manipulating the offset to crazy values and the resultant getOrigin() changes in accordance:

Example (monster_zombie_security_pistol.af):

body "waist" {
joint "origin"
mod orientation
model box( ( -5.5, -7.5, -6 ), ( 5.5, 7.5, 6 ) )
origin ( 0, 0, 44 )

   
As promised here is a script that works around the problem. It seems to work pretty well, but has not been exhaustivly tested:

A working solution to your problem is here:

sys.print( "Started: monster_zombie_base::state_Killed()\n" );

// ***************************************************
// ***************************************************
// Variables
entity myFX;
vector newFXOrigin;
float traceDistance;
vector beginTracePoint;
vector endTracePoint;
float traceFrac;

// Set values
traceDistance = 64.0; // Only trace this far to be realistic

// At this point the AI origin will be several units up off the floor
beginTracePoint = self.getWorldOrigin();

endTracePoint = beginTracePoint;
endTracePoint_z = endTracePoint_z - traceDistance;

// Trace down by traceDistance units to try and find something solid under us
traceFrac = sys.trace( beginTracePoint, endTracePoint, '0 0 0', '0 0 0', MASK_SOLID|CONTENTS_RENDERMODEL, self );

// Using the trace fraction from the trace we work out how many units to move the FX down
newFXOrigin = beginTracePoint;
newFXOrigin_z = newFXOrigin_z - ( traceFrac * traceDistance );

// Here we drop the decal using the spawned FX entity
sys.setSpawnArg( "fx", "fx/arx_blood_pool" );
sys.setSpawnArg( "start", "0" );
sys.setSpawnArg( "triggered", "1" );
myFX = sys.spawn( "func_fx" );
myFX.setOrigin( newFXOrigin );

sys.trigger( myFX );

// ***************************************************
// ***************************************************


Cheers