# Player Rope Swing?

I'm trying to implement a rope swinging mechanism for my custom UDK Pawn class. What I am trying to do is have the player be able to attach and swing as if by a rope attached to a hook entity in the map.

Searching online I managed to find this article which perfectly captures what I am trying to accomplish, but where I need help is implementing it specifically in UDK with the pawn class.

Two requirements I have are that it isn't done using physical simulation and should be able to work in a network multiplayer environment.

This is my attempt at implementing the technique presented in the article in UDK:

class UTPawn_Grapple extends UTPawn;

DefaultProperties
{
}

simulated event Tick(float DeltaTime)
{
local UTPlayerController_Grapple myController;
local vector testPosition;

myController = UTPlayerController_Grapple(self.Controller);
testPosition = Location + (Velocity * DeltaTime);

if (myController.TargetedHook != None)
{
if (VSize(testPosition - myController.TargetedHook.Location) >= myController.TargetedHook.ropeLength)
{
testPosition = Normal(testPosition - myController.TargetedHook.Location) * myController.TargetedHook.ropeLength;
Velocity = (testPosition - Location) / DeltaTime;

WorldInfo.Game.Broadcast(self, "Velocity: " $string(Velocity)); // DEBUG WorldInfo.Game.Broadcast(self, string(Location)$ "-->" \$ string(testPosition)); // DEBUG
}
}

Super.Tick(DeltaTime);
}


Unfortunately the resulting behaviour is that my character rapidly accelerates towards a specific point on the map that is far from the hook and far outside the rope length, each time it's always the same point.

And here is the debug info output I get during this:

One thing that stands out to me is the huge velocity vectors, but why am I getting numbers these big? Why is my character always pushed towards this seemingly arbitrary point on the map?

So my big question is: How can I fix this implementation or is there a better way to do it?

• the obvious questions: are the units the same magnitude and type ? Rounding errors ? Is the algorithm really the same as the one mentioned in the link you gave ? (At quick glance, it looks different to me. ... but that's only a glance!) – Howard Pautz Sep 3 '13 at 19:40
• @HowardPautz I'm assuming vectors in UDK are measured in some kind of proprietary "Unreal Unit". What I'm not so sure about is if velocity is measured the same way in the physics engine. I'm also not sure if my algorithm is the same as the article's since the author's code snippets seem to be broken up into smaller components of one algorithm and I'm assuming that his code was written for use in a 2D situation although I'm fairly certain it will work in 3D without any changes other than vectors are now 3D. – Kyle V. Sep 3 '13 at 20:29
• What I'd probably do is extract as much as possible into simpler code where I know what's going on, then test that. Something about the math algo isn't sitting right with me, but I can't place it without testing ... looks like you might be getting acceleration instead of velocity ? – Howard Pautz Sep 3 '13 at 21:17
• Unreal Unit --- faster than a speeding complex number, able to leap infinitesimals in a single bound ! Look up in the sky! It's Unreal Unit !! – Howard Pautz Sep 3 '13 at 21:19
• @HowardPautz From Unreal Wiki: ...Distances, brush dimensions and collision cylinder sizes are always measured in UU (Unreal Units), velocities in UU per game second and so on. I don't know what a "game second" is however, does it mean 1 frame? Also I don't think I'm getting Acceleration since it's distance over time (or deltaTime rather). – Kyle V. Sep 3 '13 at 21:55

 testPosition = Normal(testPosition - myController.TargetedHook.Location) * myController.TargetedHook.ropeLength;

testPosition = myController.TargetedHook.Location + (Normal(testPosition - myController.TargetedHook.Location) * myController.TargetedHook.ropeLength);