Is there a way to smooth out the look of objects in the users hand when moving in continuous movement? Both objects look quite jerky and its not from lag. I’m using velocity tracking and want the object to object interaction
thanks,
Vanz
Is there a way to smooth out the look of objects in the users hand when moving in continuous movement? Both objects look quite jerky and its not from lag. I’m using velocity tracking and want the object to object interaction
thanks,
Vanz
You probably need to update the position of the objects in LateUpdate as well as Update, since that’s what your hand-trackers do.
You might also need to use Script Execution Order to make sure your object-position-updater runs after the hand tracker.
Thanks JoeStrout,
Tried various Update, FixedUpdate, LateUpdate order and code placement and played around with smoothing Track position (see below pic) but I still get a very jerky object moving around in my hand with continuous movement, see below script.
What does fix it, is if I change my object from “Velocity” tracking to “Instanteous” tracking but then I lose the good physic interactions.
Could really use some help/guidance on this…
I’m at the point where I am thinking of changing all my objects to Instanteous tracking and adding an extra big capsule collider, then when this big new collider touches something, I switch the object from Instanteous to Velocity tracking, and back again on ExitCollision, but this feels like the wrong thing to do…
Thanks,
Vanz
using System.Collections;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
public class ContinousMovement : MonoBehaviour
{
public float speed = 1.0f;
public XRNode inputSource;
public float gravity = -9.81f;
public LayerMask groundLayer;
public float additionalHeight = 0.2f; // height of headset
private float fallingSpeed;
private XRRig rig;
private Vector2 inputAxis;
private CharacterController character;
// Start is called before the first frame update
void Start()
{
character = GetComponent<CharacterController>();
rig = GetComponent<XRRig>();
}
// Update is called once per frame
void Update()
{
InputDevice device = InputDevices.GetDeviceAtXRNode(inputSource);
device.TryGetFeatureValue(CommonUsages.primary2DAxis, out inputAxis);
} // end update
/*
void LateUpdate()
{
InputDevice device = InputDevices.GetDeviceAtXRNode(inputSource);
device.TryGetFeatureValue(CommonUsages.primary2DAxis, out inputAxis);
} // end update
*/
//void Update()
//void LateUpdate()
private void FixedUpdate()
{
CapsuleFollowHeadset();
Quaternion headYaw = Quaternion.Euler(0, rig.cameraGameObject.transform.eulerAngles.y, 0);
Vector3 direction = headYaw * new Vector3(inputAxis.x, 0, inputAxis.y);
character.Move(direction * Time.fixedDeltaTime * speed);
// gravity
bool isGRounded = CheckIfGrounded();
if (isGRounded)
fallingSpeed = 0;
else
{
fallingSpeed = fallingSpeed + gravity * Time.fixedDeltaTime;
character.Move(Vector3.up * fallingSpeed * Time.fixedDeltaTime);
}
}
void CapsuleFollowHeadset()
{
character.height = rig.cameraInRigSpaceHeight + additionalHeight;
Vector3 capsuleCenter = transform.InverseTransformPoint(rig.cameraGameObject.transform.position);
character.center = new Vector3(capsuleCenter.x, character.height / 2 + character.skinWidth, capsuleCenter.z);
}
bool CheckIfGrounded()
{
// see if on ground or not, use a sphere cast
Vector3 rayStart = transform.TransformPoint(character.center);
float rayLength = character.center.y + 0.40f;//0.05f; was this - this offsets from real Oculus head set height to ground
//rayLength = 2.0f;
bool hasHit = Physics.SphereCast(rayStart, character.radius, Vector3.down, out RaycastHit hitInfo, rayLength, groundLayer);
//Debug.Log("character.center.y = " + character.center.y);
return hasHit;
}
}
You’re not going to get smooth physics object handling with the xr tool kit without additional work to make your hands physically based.
oh great, help from a salesman… ![]()
I really don’t want to learn another whole new system created by some dude that may or may not support his asset in 12 months from now…
I don’t use the XR toolkit but this is exactly how I am doing this. I do a sphere overlap and if I get a hit I switch to moving with velocity. Otherwise, it is instant. In real life, if you hold something and run it is going to move with at the same velocity as your hand, it doesn’t lerp, it instantly moves. Only benefit to moving with velocity is if it is hitting something because if it is kinematic it will not give you the desired effect.
However, if you do want smooth movement, you would want to use the same Update (fixed, late, normal etc.) loop as the body (what ever is moving the XR rig) and the same delta time. Keep in mind that when you move a rigidbody that rigidbody.position may not be the same position as transform’s rendered position. Those gets updated in different loops. Faster you go, higher the discrepancy will be, which is what shows up as jitter.
thanks FlightOfOne, will need to experiment on this, thanks…