Jump to content

Delta Position And Rotation


MackeyK24
 Share

Recommended Posts

Yo @Deltakosh ... I got a DELTA question for you...

When the industry uses terms like 'delta' position and rotation , is that just the current position and rotation SUBTRACT the last position and rotation. ???

Is it ALWAYS SUBTRACTED from even with negative values ???

I got my Animation System going pretty good so far (except blend trees) I even now have a real Root Motion system where the motion (translation and rotation) of the root transform actually drives the movement of the character... its supposed to provide better animated move since you not syncing the animation with the movement of the container object (including speed or magnitude)... but the animations 'root motion' drives the movement of the container.

In unity...The Animator Component has runtime properties you would use to 'apply. root motion' to your character:

animator.rootPosition

animator.rootRotation

animator.deltaPosition

animator.deltaRotation

If your just wanna translate your container mesh around, in an update loop your do something like this:

transform.position = animator.rootPosition;
transform.rotation = animator.rootRotation;

and to move with velocity:

Vector3 v = (animator.deltaPosition * moveSpeedMultiplier) / this.manager.deltaTime;
// we preserve the existing y part of the current velocity.
v.y = physicsImposter.getLinearVelocity().y;
physicsImposter.setLinearVelocity(v);

I can't find were they actually calculate 'deltaPosition' but I assume that is current position SUBTRACT lastPosition...

How would I code keeping a position delta with the vector ref stuff:

private _rootPosition:Vector3
private _lastPosition:Vector2
private _deltaPosition:Vector2

public get deltaPosition():Vector3 {
  return this._deltaPosition;
}

// A Fixed Update After Render Loop
protected fixed() : void {
  this._rootPosition.substractToRef(this._lastPosition, this._deltaPosition);
  this._lastPosition.x = this._rootPosition.x;
  this._lastPosition.y = this._rootPosition.y;
  this._lastPosition.z = this._rootPosition.z;
  
}

then I could either use the Root Motion position and rotation directly OR use Root Motion Delta position and time where I need to accumulate the position and rotation... like setting velocity on physics for movement.

Link to comment
Share on other sites

10 minutes ago, adam said:

I think it makes more sense to add delta.

Edit:  Sorry, yes that is how you compute delta.

Kool... So just to clarify (before I got putting it in the toolkit to calc the delta for the root motion of the current playing animation) I wanna make sure..

 

These are my two delta updaters... They update the the "state machine" metadata directly... this is the same spot the state machine uses for state machine parameter that you create in the animator editor window... Like Forward, Turn, IsGounded etc (like unity uses).. They should be Kool:

        private updateDeltaPosition():void {
            if (this.owned.metadata != null && this.owned.metadata.state != null && this.owned.metadata.state.deltaPosition != null && this.owned.metadata.state.lastPosition != null && this.owned.metadata.state.rootPosition != null) {
                               this.owned.metadata.state.rootPosition.subtractToRef(this.owned.metadata.state.lastPosition, this.owned.metadata.state.deltaPosition);
                this.owned.metadata.state.lastPosition.x = this.owned.metadata.state.rootPosition.x;
                this.owned.metadata.state.lastPosition.y = this.owned.metadata.state.rootPosition.y;
                this.owned.metadata.state.lastPosition.z = this.owned.metadata.state.rootPosition.z;
            }
        }
        private updateDeltaRotation():void {
            if (this.owned.metadata != null && this.owned.metadata.state != null && this.owned.metadata.state.deltaRotation != null && this.owned.metadata.state.lastRotation != null && this.owned.metadata.state.rootRotation != null) {
                this.owned.metadata.state.rootRotation.subtractToRef(this.owned.metadata.state.lastRotation, this.owned.metadata.state.deltaRotation);
                this.owned.metadata.state.lastRotation.x = this.owned.metadata.state.rootRotation.x;
                this.owned.metadata.state.lastRotation.y = this.owned.metadata.state.rootRotation.y;
                this.owned.metadata.state.lastRotation.z = this.owned.metadata.state.rootRotation.z;
            }
        }

 

First I subtract the lastPosition from the current rootPosition as current delta position

Then I set the last position buffers to the current root position buffers for evaluation next frame

but current delta position should be right in the 3d game world as 'Delta Position' ... Is that correct (I'm still newbie to 3d game programming and I can't seem to find anywhere in unity docs about exactly the calculation for this Root Motion Delta)

 

.. Dude... Thanks for the help :)

 

Link to comment
Share on other sites

BTW.. the above code test... so far... I have working Root Motion with translation movement and physics movement... SO FAR :)

EDIT: I take that back... Rotation is fuckup... But that just me and rotations... I always have problems with rotations :(

But the concept seems to be working... I will keep working on it...

Root Motions seem to be the way the industry is change to... Almost all the Mixamo animations are Root Motion and only a few have the option to download an in-place version of it.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...