Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

Gameplay.Catapult


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
///////////////////////////////////////////////////////////////////////////////
// Catapult
//
// Applies an impulse to certain objects when they touch it - Characters, time delayed
// projectiles, and inventory items.
//
class Catapult extends BaseDevice dependsOn(Character);

var(Catapult) float		throwForce				"How much force is imparted to an actor that uses the catapult?";
var(Catapult) float		actorInfluence			"How much does the linear velocity of the actor influence the throw direction?";
var(Catapult) float		catapultInfluence		"How much does the catapult's orientation influence the throw direction?";
var(Catapult) bool		bDirectional			"Does the catapult only throw in a forward direction (x axis)?";
var(Catapult) float		verticalInfluence		"(Directional only) What is the vertical influence of catapult? (0.0 = horizontal, 1.0 = vertical)";
var(Catapult) bool		bIgnoreActorVelocity	"Set to ignore the actor velocity when it hits the catapult (ie: force the actor in the direction the catapult throws)";
var(Catapult) bool		bReflective				"Does the catapult reflect the actor velocity in to the velocity out? (Setting this to true results in all other variables being ignored)";

replication
{
	reliable if(Role == ROLE_Authority)
		throwForce, actorInfluence, catapultInfluence, bDirectional, 
		verticalInfluence, bIgnoreActorVelocity, bReflective;
}

simulated function Touch(actor Other)
{
	// arc projectiles handle catapult touching from their end
	if (Other.IsA('ArcProjectile'))
		return;

	TouchProcessing(Other);
}

simulated function TouchProcessing(actor Other)
{
    local float actorMass;               // mass of actor in kilos
    local Vector actorVelocity;          // incoming actor velocity

    local Vector desiredVelocity;        // desired outgoing actor velocity (minus throw impulse)
    local Vector desiredDirection;       // desired outgoing direction vector (zero if ignoring incoming velocity)

	local Vector throwImpulse, throwDirection;
	local Vector catapultForward, catapultRight, catapultUp;

	if(! isFunctional() || isAnimating())
		return;

	if(Other.Role != ROLE_AutonomousProxy && Other.Role != ROLE_Authority && !Other.IsA('ArcProjectile'))
		return;

	//
	// Check that we have a throwable actor
	//
	if(! (Other.IsA('Character') || 
		  Other.IsA('KActor') || 
		  Other.IsA('ArcProjectile')))
				return;

	//
	// Get the zAxis of the catapult for the throw Impulse direction
	//
	GetAxes(Rotation, catapultForward, catapultRight, catapultUp);

    actorVelocity = other.unifiedGetVelocity();

	if(! bReflective)
	{
		//
		// Get the adjusted actor velocity (remove components facing towards 
		// the catapult throw direction) and store a normalized version.
		//
		if(bIgnoreActorVelocity)
		{
			desiredVelocity = vect(0,0,0);
			desiredDirection = vect(0,0,0);
		}
		else
		{
		    // remove velocity component into catapult (inelastic collision)
		
			desiredVelocity = actorVelocity - (actorVelocity dot catapultUp) * catapultUp;
			desiredDirection = Normal(actorVelocity);
		}

		if(bDirectional)
		{
			//
			// If this is a directional catapult we want to restrict the throw 
			// direction to the plane of the catapult. 
			//
			// note: throw will always be in the direction of the forward axis.
			//
			throwDirection = (catapultUp * verticalInfluence) + (catapultForward * (1.0 - verticalInfluence));
		}
		else
		{
			//
			// Use a throw direction calculated from the catapult influence and the
			// actor influence (inelastic collision response outgoing direction)
			//
			throwDirection = Normal((catapultUp * catapultInfluence) + 
									(desiredDirection * actorInfluence));
		}
	}
	else
	{
		//
		// A collision with a reflective catapult should result in the outgoing 
		// velocity of the player to be an opposite reflection of the incoming
		// velocity, around the plane of the catapult base. This should be perfectly elestic. 
		//
		
		desiredVelocity = MirrorVectorByNormal(actorVelocity, catapultUp);

		throwDirection = Normal(desiredVelocity);
	}

	// calc the throw impulse
	throwImpulse = throwForce * throwDirection;

	// extra step to even out the impulse so that all objects  
	// behave the same way when they touch a catapult (may filter
	// this step by class later if required).
    actorMass = other.unifiedGetMass();
	throwImpulse = (throwImpulse * actorMass) / 100;

    if (Character(other)!=None)
        Character(other).blockMovementDamage = true;

    other.unifiedAddImpulse(throwImpulse + (desiredVelocity - actorVelocity) * actorMass);

	PlayBDAnim('Fire');
	
	TriggerEffectEvent('CatapaultTriggered', Other, None, Location, Rotation);
}

defaultproperties
{
	Mesh = SkeletalMesh'BaseObjects.Catapult'
	DrawType = Mesh

	RemoteRole=ROLE_DumbProxy

	bBlockActors = false
	bBlockPlayers = false

	bReplicateAnimations = true;

	bBlockKarma = false
	bBlockHavok	= false

	bIgnoreActorVelocity = false;

	throwForce = 400000.0
	actorInfluence = 0.0		// default to no actor influence
	catapultInfluence = 1.0		// full catapult influence

	bDirectional = false;		// default to a non-directional catapult
	verticalInfluence = 0.5;	// default to 45 degrees

	bReflective = false;

	bWorldGeometry = false
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: ne 5.9.2004 15:53:20.000 - Creation time: st 23.5.2018 00:10:42.683 - Created with UnCodeX