PDA

View Full Version : Moving a pawn round a circle



thelaw
10-23-2010, 03:33 AM
I have an object which has a handle sticking out, I want my pawn to use the handle to turn the object while moving around the circle. Here is a diagram of my setup

http://www.twistedlogicgames.com/3dimages/Move_Pawn_In_Circle.png

I believe I need to calculate a directional vector based on the inputs. I have my radius which is the distance from the center of the object to my pawns position. How can I calculate this vector?

Kuroi
10-23-2010, 03:38 AM
Look at this thread:
http://forums.epicgames.com/showthread.php?t=747518

Kuroi
10-23-2010, 03:50 AM
Or you may do like that:


.
.
.
local vector loc, newloc;
local rotator rot;
local float radius;

rot = pawn.rotation; // angle
loc = pawn.location; // center of circle

newloc = loc + (vector(rot)*radius);
.
.
.

thelaw
10-23-2010, 07:30 AM
Perhaps you misunderstood (or I misunderstood your answer) I don't want to rotate the pawn, but rather have it move along a circular path. The centre of the circle is actually the other object's location. I'm using a UDKSkelControl_Rotate so perhaps I could use your code with the current bone's rotation.

I also already had a look at the thread earlier but in that case the actor's position is being set manually, I'm trying to figure out the vector so in the PlayerController's PlayerMove function, I can multiply this vector by Pawn.AccelRate and let the Pawn try to move in that direction.

I've plugged in some values just to try understand how its supposed to work and here is a snippet from my PlayerMove function.



/// AngleTheta = 20 is change in angle
Angle += AngleTheta;
if(Angle > 360)
Angle -= 360;

Pos.X = Cos(Angle * DegToRad) * Radius + CurrentlyUsedItem.Location.X;
Pos.Y = Sin(Angle * DegToRad) * Radius + CurrentlyUsedItem.Location.Y;
Pos.Z = 0;

/// we should move to Pos
Dir = Normal(Pawn.Location - Pos);
NewAccel = Pawn.AccelRate * Dir;

The idea is, on input, I increment the angle, use this angle to figure out where the pawn should move to. Subtract the pawn's current position from the desired position and normalize the result to get a direction. Then multiply this direction by the Pawn's acceleration and use this to move.

The Pawn moves but within a very small radius and not around the object.

Triggered
10-23-2010, 11:32 AM
I think angles in UDK are done between 0 and 60,000 rather than between 0 and 360. I don't know why.

thelaw
10-23-2010, 11:40 AM
I think angles in UDK are done between 0 and 60,000 rather than between 0 and 360. I don't know why.

It's to avoid inaccuracies of floating point numbers. You can still use degrees and radians (radians are expected by the sin/cos functions) you only use the 0-65536 range with rotators.

Triggered
10-23-2010, 01:15 PM
It's to avoid inaccuracies of floating point numbers. You can still use degrees and radians (radians are expected by the sin/cos functions) you only use the 0-65536 range with rotators.

Oh ok, thanks for clearing that up. I'm new to unreal script.

thelaw
10-24-2010, 05:00 AM
I made a bit of progress, problem with my previous code is that I was calculating the desired direction the wrong way

Pawn.Location - Pos
as opposed to

Pos - Pawn.Location
since the Pawn is my point of reference and I'm looking for a direction to my desired position.

Here is my final code that moves the pawn round the circle but as always, I now have a new problem, my pawn jitters as it moves along. Any ideas why?


Pos.X = Cos(Angle * DegToRad) * Radius + CurrentlyUsedItem.Location.X;
Pos.Y = Sin(Angle * DegToRad) * Radius + CurrentlyUsedItem.Location.Y;
Pos.Z = Pawn.Location.Z;

// we're rotating at 20 degress per second so scale by delta time
Angle = AngleTheta * DeltaTime;
if(Angle > 360)
Angle -= 360;

/// we should move to Pos
Dir = Normal(Pos - Pawn.Location);

// Update acceleration.
NewAccel = Pawn.AccelRate * Dir;

thelaw
10-24-2010, 05:31 AM
Here I am talking to myself again, please excuse me.

The jittering doesn't occur with a larger angle/second value and radii (never thought I would have to write the plural of radius in this lifetime). I believe a smaller value results in the pawn being moved to a position further than what we expect and then being brought back in the next frame.

At the moment I will just use larger values but perhaps a solution would be to set a lower ground speed so the pawn is not moved too far.

Tymora
10-26-2010, 03:31 AM
I have an idea you may want to try.
You could make a socket on the rotating object, and then attach the player to it.

Actually, I'm having the same problem with my code.
But if you can get it to run as smoothly as possible, add a vlerp between the current position and the calculated position.

thelaw
10-26-2010, 03:02 PM
I have an idea you may want to try.
You could make a socket on the rotating object, and then attach the player to it.
Thanks for the tip, I tried it and though the mesh gets attached, the rest of the pawn is left behind.

I want to try and figure out just how far a pawn can move every tick and move both my pawn and the object in sync.

Kinos
10-26-2010, 03:08 PM
I think angles in UDK are done between 0 and 60,000 rather than between 0 and 360. I don't know why.

0 to 65536 to be exact. or to be more exact 0 to 0.:D

toxicFork
10-26-2010, 04:02 PM
it's because it's easier to send integers than floating points through networking.