View Full Version : What is DeltaTime in Unrealscript?
01-07-2011, 02:48 PM
I keep seeing parameters to methods called DeltaTime but I'm not sure what that is or how I get that. I want to invoke a method that takes DeltaTime but I'm not sure what DeltaTime is but I see that being passed all over the place.
Is it just the change in time since some other event occurred?
For instance, here is a method I want to call in PlayerController.uc
function ProcessMove(float DeltaTime, vector NewAccel, eDoubleClickDir DoubleClickMove, rotator DeltaRot)
if( Pawn == None )
if (Role == ROLE_Authority)
// Update ViewPitch for remote clients
Pawn.SetRemoteViewPitch( Rotation.Pitch );
Pawn.Acceleration = NewAccel;
01-07-2011, 02:53 PM
DeltaTime is a change in time, usually since the last frame or update. PlayerMove() should be called every tick (from PlayerTick() I think?) by default so I can't really see why you would ever need to specifically call that function. What is it you are trying to do?
01-07-2011, 02:53 PM
Delta denotes a change (for example, a change in time since something was last executed, time2 - time1). For example, with footsteps, you don't want footsteps ocurring 60 times a second, you want to limit it and adjust it to the animation length where the foot hits the ground (ie. the perfect time for playing a footstep sound cue)
01-07-2011, 03:08 PM
I am attempting to just move the player each frame with the motion controls but I need some way to set the movement direction of the player. I'm having trouble figuring out which variables or methods control the movement of the player.
01-07-2011, 03:13 PM
Here's how player movement prediction, replication and correction works in network games:
Every tick, the PlayerTick() function is called. It calls the PlayerMove() function (which is implemented
in various states). PlayerMove() figures out the acceleration and rotation, and then calls ProcessMove()
(for single player or listen servers), or ReplicateMove() (if its a network client).
ReplicateMove() saves the move (in the PendingMove list), calls ProcessMove(), and then replicates the move
to the server by calling the replicated function ServerMove() - passing the movement parameters, the client's
resultant position, and a timestamp.
ServerMove() is executed on the server. It decodes the movement parameters and causes the appropriate movement
to occur. It then looks at the resulting position and if enough time has passed since the last response, or the
position error is significant enough, the server calls ClientAdjustPosition(), a replicated function.
ClientAdjustPosition() is executed on the client. The client sets its position to the servers version of position,
and sets the bUpdatePosition flag to true.
When PlayerTick() is called on the client again, if bUpdatePosition is true, the client will call
ClientUpdatePosition() before calling PlayerMove(). ClientUpdatePosition() replays all the moves in the pending
move list which occured after the timestamp of the move the server was adjusting.
The PlayerMove() function in the PlayerWalking state is the main location where the player input is converted into movement. You could override that to use the motion input data, using the existing code as a guide.
01-07-2011, 03:46 PM
Ahahah, I was just studying the mathematical concepts of movement predictions using polynomials in networked games, real useful, Mr. Jeff, thanks!
01-07-2011, 04:31 PM
Thanks, that helps a lot. With your help I ended up coming up with a solution to the movement problem with the movement controls. I'm working on a top down game where the top down view is fixed.
DeviceAttitude is a class vector variable.
function PlayerMove(float DeltaTime)
// Device Attitude.X is forward and backwards.
// Device Attitude.Z is left and right
Pawn.Acceleration.X = DeviceAttitude.X * -0.5f;
Pawn.Acceleration.Y = DeviceAttitude.Z * 0.5f;
Pawn.Acceleration.Z = DeviceAttitude.X * 0;
Pawn.Acceleration = Pawn.AccelRate * Normal(Pawn.Acceleration);
ProcessMove(DeltaTime, Pawn.Acceleration, DCLICK_None, rot(0,0,0));
function UserTiltingDevice(PlayerInput pInput, vector CurrentAttitude, vector CurrentRotationRate, vector CurrentGravity, vector CurrentAcceleration)
local bool shouldBeWalking;
shouldBeWalking = false;
DeviceAttitude = CurrentAttitude;
if(DeviceAttitude.X < 0.05f && DeviceAttitude.X > -0.05f)
DeviceAttitude.X = 0;
shouldBeWalking = true;
if(DeviceAttitude.Z < 0.05f && DeviceAttitude.Z > -0.05f)
DeviceAttitude.Y = 0;
shouldBeWalking = true;
if(logCount % 30 == 0)
`Log("Current Attitude: " $CurrentAttitude);
`Log("Rotation Rate: " $CurrentRotationRate);
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.