Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where are the visuals updated? car experiment download
#1
Hi

i managed to get custom physics working with OnBeginStep and it is working nicely
now the visuals are lagging behind, where is that updated?

as you can see in the video the visual representation of the softbody lags behind the wheels and camera, both updated in OnBeginStep

thanks
Reply
#2
(17-03-2023, 02:43 PM)tegleg Wrote: Hi

i managed to get custom physics working with OnBeginStep and it is working nicely
now the visuals are lagging behind, where is that updated?

as you can see in the video the visual representation of the softbody lags behind the wheels and camera, both updated in OnBeginStep

thanks

Hi,

Visuals are updated once at the end of each frame, in LateUpdate, at the end of the solver's physics state interpolation. The corresponding event in the solver is OnInterpolate: http://obi.virtualmethodstudio.com/manua...olver.html

Because of this, it's not possible for visuals and the particle simulation to get out of sync. Chances are the actual simulation of softbody is out of sync with your rigidbody physics. How and when are you updating the soft body's position?

kind regards,
Reply
#3
OnInterpolate, ok i will try that. thanks

there are no rigidbody physics. it is raycasts from the corner particles with a simulated spring updated in OnBeginStep, this also updates the forward force on the particle
i am doing nothing with the softbody besides adding forces.

the wheels are just a visual representation placed at the end of the raycast updated in OnBeginStep

i did try constraining the softbody to a rigidbody vehicle but the softbody can 'fall off' the rigidbody in certain situations.
raycast works very well from a physics standpoint
Reply
#4
i cant get it to work properly so i am giving away what i have done. I know there are lots of questions about making a car with obi and this is the closest i have seen so far.
maybe somebody can work out what is going wrong. please reply if you fix it.

the car code is based on the old unity 3 advanced car scripts.

the softbody car body has 4 particle groups, fl, fr, rr, rl, each containing 1 particle. SBCarWheel looks for this particle (GroupIndex) and starts a raycast from and applies forces to it.
the physics part is working fine (more spring damping needed). the visuals of the softbody lags behind for an unknown reason.

the code is rough, it is a sketch of an idea rather than a complete solution, some parts are wrong/placeholders such as velocity calcs but that doesnt matter for testing. i am abandoning it for now as i have too many other projects on the go and this is distracting me
if you take the idea and run with it to make a great game that is up to you, the idea is there, the potential is there, make of it what you will

import obi softbody to a new project - import the attached package - open cartest scene
download package

have fun
Reply
#5
(17-03-2023, 09:24 PM)tegleg Wrote: i cant get it to work properly so i am giving away what i have done. I know there are lots of questions about making a car with obi and this is the closest i have seen so far.
maybe somebody can work out what is going wrong. please reply if you fix it.

the car code is based on the old unity 3 advanced car scripts.

the softbody car body has 4 particle groups, fl, fr, rr, rl, each containing 1 particle. SBCarWheel looks for this particle (GroupIndex) and starts a raycast from and applies forces to it.
the physics part is working fine (more spring damping needed). the visuals of the softbody lags behind for an unknown reason.

the code is rough, it is a sketch of an idea rather than a complete solution, some parts are wrong/placeholders such as velocity calcs but that doesnt matter for testing. i am abandoning it for now as i have too many other projects on the go and this is distracting me
if you take the idea and run with it to make a great game that is up to you, the idea is there, the potential is there, make of it what you will

import obi softbody to a new project - import the attached package - open cartest scene
download package

have fun

Hi!

There's a couple problems:

1.- The camera is looking at the car in Update(), so it lags behind the car which has its transform updated in LateUpdate() (which is where OnInterpolate happens). The camera should look at the car during OnInterpolate, which ensures the car's transform has already been updated that frame by the time the camera looks at it.

2.- The solver has interpolation enabled, which naturally introduces 1-frame delay of visuals with respect to physics state (same as with rigidbody interpolation in Unity, and most physics engines). See the warning about interpolation in the manual: http://obi.virtualmethodstudio.com/manua...olver.html

Replace the CamLookAt script with this one:

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class CamLookat : MonoBehaviour
{

    public ObiSoftbody car;

    // Start is called before the first frame update
    void OnEnable()
    {
        car.OnInterpolate += Car_OnInterpolate;
    }

    void OnDisable()
    {
        car.OnInterpolate -= Car_OnInterpolate;
    }

    private void Car_OnInterpolate(ObiActor actor)
    {
        transform.LookAt(car.transform);
    }

}

And set interpolation to "None" in the ObiSolver component. This will result in buttery smooth car and camera (I'm really bad at driving this thing so apologies in advance!). Also had to comment out all skidmark-related code in the package since there seems to be missing components, so I guess no skid marks in the video:

Reply
#6
thanks for taking a look
disabling interpolation certainly smooths out the softbody. i accidentally left that enabled from rigidbody experiments

the visual wheels still drift ahead of the body though. the models must be missing from the package download.
put a mesh in WheelFR - Tire Front Right for example and you will see. the faster the car goes the further ahead the wheels are

i think in the package it is SBCarWheel script OnEndStep, it is the same if i change it to OnInterpolate
also increase Grip on the wheels to make it easier to drive

it is so close to being a useable car with your fantastic softbody solution
Reply