19-03-2023, 07:03 PM
(This post was last modified: 19-03-2023, 07:08 PM by josemendez.)
(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: