PDA

View Full Version : How to? - Add interaction



100GPing100
02-20-2011, 08:24 AM
This is for my Viper import from UT3, I made an interaction to change the vehicle's speed when the jump key is being pressed:

UT3ViperInteraction.uc

class UT3ViperInteraction extends Interaction;

var UT3Viper2v Viper;

simulated function bool KeyEvent(out Interaction.EInputKey Key, out Interaction.EInputAction Action, FLOAT Delta)
{
local string KeyName, KeyBind;

KeyName = ViewportOwner.Actor.ConsoleCommand("keyname "$int(Key));
KeyBind = ViewportOwner.Actor.ConsoleCommand("keybinding "$KeyName);

if (KeyBind ~= "Jump")
{
if (Action == IST_Press)
{
Viper.AirSpeed *= 0.001;
Viper.GroundSpeed *= 0.001;
}
else if (Action == IST_Release)
{
Viper.AirSpeed = Viper.default.AirSpeed;
Viper.GroundSpeed = Viper.default.GroundSpeed;
}
}

return false;
}

defaultproperties
{
bVisible=True
bRequiresTick=True
}

I want to add this interaction to the Viper's driver interactions, how can this be done?

In the Jetpack mutator, the interaction is added to the player with this code in the jetpack inventory:

if (AttachedPlayer.Player != None)
{
for (i = 0; i < AttachedPlayer.Player.LocalInteractions.Length; i++)
{
if (AttachedPlayer.Player.LocalInteractions[i].IsA('JetpackInteraction'))
{
if (!bD) JetpackInteraction(AttachedPlayer.Player.LocalInte ractions[i]).TrapJetpackMovement(Self, bOn);
else JetpackInteraction(AttachedPlayer.Player.LocalInte ractions[i]).TrapJetpackMovement(None, bOn);
b = true;
break;
}
}

if (!b && (AttachedPlayer.Player.InteractionMaster != none))
{
AttachedPlayer.Player.InteractionMaster.AddInterac tion("Jetpack.JetpackInteraction", AttachedPlayer.Player);
for (i = 0; i < AttachedPlayer.Player.LocalInteractions.Length; i++)
{
if (AttachedPlayer.Player.LocalInteractions[i].IsA('JetpackInteraction'))
{
if (!bD) JetpackInteraction(AttachedPlayer.Player.LocalInte ractions[i]).TrapJetpackMovement(Self, bOn);
else JetpackInteraction(AttachedPlayer.Player.LocalInte ractions[i]).TrapJetpackMovement(None, bOn);
break;
}
}
}
}

There they add the interaction to the attached player. for me the attached player would be what? I don't know what I should reference as the player driving the Viper.

Conclusion: I want to know how I add this interaction to what is driving the Viper.

GreatEmerald
02-20-2011, 08:39 AM
PlayerController(Controller).

100GPing100
02-20-2011, 09:52 AM
Thanks :D ..

meowcat
02-20-2011, 11:14 AM
Rather than screwing with adding an interaction (which is not a bad coding exercise in and of itself) I think you could accomplish what you are aiming for by simply placing the speed adjustment code in the KApplyForce function of your subclassed manta instead (this will keep things cleaner overall).

[EDIT] Actually you could probably just look at the value of 'Rise' to see if it is greater than 0 to check if the player is trying to move up/jump.

100GPing100
02-20-2011, 11:48 AM
I do use Rise > 0 to check jump. the problem is:

when it gets to the part of cahnging the vehicle's velocity, it does nothing. The code does get called, but nothing more, the velocity stays the same.

GreatEmerald
02-20-2011, 12:06 PM
And what makes you think that an interaction will help?..

100GPing100
02-20-2011, 12:52 PM
The interaction was to make some aniations and stuff, I tought it would be difrent, but it is the same thing.