UE3 - UDK Math problem

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

-ErrorX-

New Member
Nov 11, 2009
8
0
0
Hi guys,
This is a problem that have very often in unreal script and I don't know how to fix it.
I'm pretty noob in mathematics. :rolleyes:

Any ways I want to move a player(Pawn) at the same speed around a pivot.

Something like this:
23jq0ya.jpg


I tried this but the bigger my offset the faster the player go's.
Code:
MyAngle.Pitch = DeltaTime * 100;
NewLocation = Pivotpoint  +  Vector(MyAngle) * offset;

I also try this and it work almost only the player is offsetting a little bit every round.
Also don't know how to put a offset in this.
Code:
GetAxes(rotator(Pivotpoint - pawn.location),X,Y,Z);
pawn.Velocity = Y * PlayerInput.aStrafe;
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
I misunderstood your question so ignore the reply I just deleted. How do want this to work exactly? Does Pawn2 turn according to the speed of Pawn1 or is the speed caused by another object?
 

-ErrorX-

New Member
Nov 11, 2009
8
0
0
The pawn has always the same ground speed only the offsets are different.
The pivot point is just a static actor in 3D space only the pawn needs is to run around this point.
So you not controlling this pawn with the mouse for the direction that you want to go.

Srry for my bad English.
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
No problem. You say the pawn needs to run around this point. Just so things are clear, do you mean that this Pawn is being moved by something else?
 

-ErrorX-

New Member
Nov 11, 2009
8
0
0
No, not by other objects. You move the pawn only whit the keyboard.
 
Last edited by a moderator:

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
49
Ah ok so it's controlled with the movement keys only like some sort of vehicle? I'm not sure how I'd do this but it will probably require trigonometry.

What you can try doing:

Circle:
-Radius
-Pi=3.1415926...
-Circumference (the line that forms the circle)

Total length of circumference 1:
- 2*pi*R
- R can be the distance of the Pawn from the center.

Distance that Pawn1 has travelled:
- Get angle of Pawn1
- Divide 360° by angle of Pawn1 = Fraction or percent of total circumference length
- Divide total distance of circle by this fraction

Place where Pawn2 should be:
- Calculate the total length of the circumference of circle 2
- Divide this value by the distance that Pawn1 has covered
- Use this value to divide 360° and get the angle of Pawn2
- Calculate the position of Pawn2

This way the absolute position of Pawn2 depends directly on the position of Pawn1. The result doesn't rely on the position of Pawn2 and there's no risk of the distance changing over time because of approximation.
 
Last edited:

-ErrorX-

New Member
Nov 11, 2009
8
0
0
Srry for my stupidity :rolleyes:
I tried to make what you said in code, but I do not really fully understand it.
This is the code that I now have:

Code:
       Angle = rotator(Pivotpoint.location - pawn.location);
       Length = VSize(Pivotpoint.location - pawn.location);
       Fraction = Angle / 65536;
       Radius = 50;

       pawn.Velocity =  Radius * Pi * (vector(Fraction) / length);
 

-ErrorX-

New Member
Nov 11, 2009
8
0
0
Sorry for bumping this topic I still try to get this to work.
Now I search on the internet for a solution and I found this:

Centripetal acceleration
centripetal_acceleration_equation.png

Bron:http://www.ajdesigner.com/phpcircularmotion/centripetal_acceleration_equation.php

Now I tried to remake this in code but still my player is offsetting every round.
Code:
     function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
    {
       local vector X,Y,Z, Dir, VelA;
       local float Radius, CentripetalAcceleration;


       Radius = 200;

      
       Dir = normal (Pivotpoint.location - pawn.location);

       Z = Dir cross vect(0,1,0);
       VelA = Z * PlayerInput.aForward;
      

       CentripetalAcceleration = (Vsize(VelA) ^ 2) / Radius;
       pawn.Velocity = (CentripetalAcceleration * Dir) - VelA;
      

       `log(Vsize(Pivotpoint.location - pawn.location)); // This need to be constant length of the Radius

    }

Here is the video of my code:
http://www.youtube.com/watch?v=lfpoLYIsOEY
 
Last edited by a moderator:

Shivan Hunter

New Member
May 29, 2009
75
0
0
Code:
MyAngle.Pitch = DeltaTime * 100;
NewLocation = Pivotpoint  +  Vector(MyAngle) * offset;

This is your original code, which moves the angle at the same speed (giving your pawns the same rotational velocity), correct?

rotational velocity, or velocity around a pivot point, is (in your terms) velocity / offset. Your code is giving the object a constant rotational velocity- so that an object twice as far from the pivot is twice as fast.

You simply need to divide your angle rotation- the MyAngle.Pitch if I'm reading the code correctly- by the offset. so your new code should be:

Code:
MyAngle.Pitch = DeltaTime * 100 / offset;
NewLocation = Pivotpoint  +  Vector(MyAngle) * offset;
 /** 100 may not work, you'll probably need a different number */

I also strongly suggest a course in basic physics. Knowing exactly how things move- especially such concepts as kinetic energy, moment of inertia (rotational motion), and momentum and collisions- is invaluable to game development. Not to mention it's quite awsum.

[EDIT] btw I like your edge detection shader
 
Last edited: