Latest Threads |
Stretching verts uniforml...
Forum: Obi Softbody
Last Post: josemendez
15-09-2025, 04:32 PM
» Replies: 1
» Views: 192
|
Scripting rod forces
Forum: Obi Rope
Last Post: chenji
11-09-2025, 01:15 PM
» Replies: 25
» Views: 3,113
|
Burst error causing crash...
Forum: Obi Rope
Last Post: josemendez
10-09-2025, 07:03 AM
» Replies: 1
» Views: 282
|
Controlling speed of emit...
Forum: Obi Fluid
Last Post: josemendez
06-09-2025, 06:29 AM
» Replies: 1
» Views: 557
|
Looks nice on editor but ...
Forum: Obi Fluid
Last Post: josemendez
04-09-2025, 07:20 AM
» Replies: 3
» Views: 796
|
How to Shorten or Scale t...
Forum: Obi Rope
Last Post: josemendez
02-09-2025, 09:53 AM
» Replies: 5
» Views: 865
|
The Limitation of Using O...
Forum: Obi Rope
Last Post: josemendez
01-09-2025, 10:30 PM
» Replies: 1
» Views: 602
|
Bug Where a Straight Segm...
Forum: Obi Rope
Last Post: josemendez
01-09-2025, 08:46 PM
» Replies: 1
» Views: 565
|
Having an issue with obi ...
Forum: Obi Rope
Last Post: Ben_bionic
29-08-2025, 04:23 PM
» Replies: 4
» Views: 1,068
|
Non-uniform particle dist...
Forum: Obi Rope
Last Post: chenji
29-08-2025, 09:05 AM
» Replies: 4
» Views: 915
|
|
|
Confused about practical use of substepping Unity Physics |
Posted by: protomenace - 22-06-2020, 05:31 AM - Forum: General
- Replies (4)
|
 |
I just got done debugging an awful bug related to sub-stepping Unity physics.
According to http://obi.virtualmethodstudio.com/tutor...aters.html, substepping Unity physics is necessary when using more than 1 substep and performing accurate collisions with Rigidbodies.
I have a game where the player controls a quadcopter drone. To simulate the propellers of my drone, I apply an upward force in FixedUpdate. I have the drone calibrated such that the force applied in FixedUpdate is equal to the mass of the drone, such that under normal circumstances, the drone perfectly hovers in place.
I've been messing around with ObiRope, and got it working somewhat well, but I found that whenever I had an Obi rope in the scene, my drone was no longer capable of hovering in place. I thought maybe the mass of an attached rope was pulling the drone down. So I started decoupling the rope and the drone. I got to a point where the two were in completely separate GameObject hierarchies, nowhere near each other in the scene, and still the presence of the rope in the scene was causing my drone to be incapable of hovering.
Then I started playing around with the ObiFixedUpdater I was using for my rope and I found that if I disabled "Substep Unity Physics" on the updater, my drone was magically able to hover again! I dug into the source code for ObiFixedUpdater and found that it directly calls https://docs.unity3d.com/ScriptReference...ulate.html. So I began to realize the issue with my drone. My drone was falling because Physics was being simulated, including gravity forces, but my FixedUpdate was not being called during this extra Physics.simulate.
I searched these forums and found this post: http://obi.virtualmethodstudio.com/forum...ml#pid6497 where it is suggested to use the ObiUpdater.OnBeginStep callback instead of FixedUpdate to apply forces. So this leaves me confused again and with more questions:
- Doesn't calling Physics.Simulate in addition to the normal unity physics update loop essentially cause Unity's physics simulation to proceed faster than realtime?
- Am I supposed to disable Physics.autoSimulation to use substepping with a FixedUpdater?
- Wouldn't I effectively get the same result from reducing Unity's physics timestep rather than doing the complicated process of substepping Unity physics and then replacing all of my FixedUpdate calls with OnBeginStep callbacks? (Or am I supposed to have FixedUpdate in addition to OnBeginStep?)
Physics substepping seems barely mentioned in passing in http://obi.virtualmethodstudio.com/tutor...aters.html, and it leaves all of these questions unaswered in my mind.
|
|
|
ObiRopeCursor.ChangeLength causes IndexOutOfRangeExceptions |
Posted by: protomenace - 20-06-2020, 05:31 PM - Forum: Obi Rope
- Replies (1)
|
 |
I'm trying to create a harpoon gun which is launched from a flying drone and hooks into whatever it collides with. The rope blueprint looks like this:
To shoot the harpoon, I'm starting with a very short rope, and increasing the length of the rope along with the velocity of the tip of my harpoon in FixedUpdate. The rope is attached to both the drone and the harpoon tip via ObiParticleAttachment.
Code: using Obi;
using UnityEngine;
public class HarpoonLauncher : MonoBehaviour
{
public ObiRopeCursor ropeCursor;
public float HarpoonVelocity = 10f;
public HarpoonTip HarpoonTip;
public Transform HarpoonConnection;
public Transform TipSpawnPosition;
public ObiSolver ObiSolver;
public ObiRope Rope;
public float InitialRopeLength = 1f;
public float MaxRopeLength = 5f;
public ObiParticleAttachment TipAttachment, DroneAttachment;
public ObiRopeBlueprint RopeBlueprint;
bool isShooting = false;
// Start is called before the first frame update
void Start() {
InitialRopeLength = Rope.restLength;
HarpoonTip.OnHarpoonEnter += WhenHarpoonImpacts;
}
private void OnDestroy() {
HarpoonTip.OnHarpoonEnter -= WhenHarpoonImpacts;
}
private void WhenHarpoonImpacts(HarpoonTip source, Collider impact) {
isShooting = false;
// Readjust length after impact
ropeCursor.ChangeLength((TipSpawnPosition.position - HarpoonTip.transform.position).magnitude + .02f);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) {
ObiSolver.gameObject.SetActive(true);
HarpoonTip.gameObject.SetActive(true);
ropeCursor.ChangeLength(InitialRopeLength);
HarpoonTip.transform.position = TipSpawnPosition.position;
Vector3 velo = TipSpawnPosition.forward * HarpoonVelocity;
HarpoonTip.Fire(velo);
//Rope.SetMass(.01f);
isShooting = true;
}
}
private void FixedUpdate() {
if (isShooting) {
Debug.Log($"{Rope.restLength}");
if (Rope.restLength >= MaxRopeLength) {
isShooting = false;
}
else {
//Rope.SetMass(.01f);
ropeCursor.ChangeLength(Rope.restLength + HarpoonTip.GetComponent<Rigidbody>().velocity.magnitude * Time.fixedDeltaTime);
//CurrentRopeLength += HarpoonTip.velocity.magnitude;
}
}
}
}
When I run this code, i get an IndexOutOfRangeExceptions in FixedUpdate after shooting the harpoon:
Quote:IndexOutOfRangeException: Index was outside the bounds of the array.
Obi.ObiActor.SwapWithFirstInactiveParticle (System.Int32 actorIndex) (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:420)
Obi.ObiActor.ActivateParticle (System.Int32 actorIndex) (at Assets/Obi/Scripts/Common/Actors/ObiActor.cs:434)
Obi.ObiRopeCursor.AddParticleAt (System.Int32 index) (at Assets/Obi/Scripts/RopeAndRod/Actors/ObiRopeCursor.cs:118)
Obi.ObiRopeCursor.ChangeLength (System.Single newLength) (at Assets/Obi/Scripts/RopeAndRod/Actors/ObiRopeCursor.cs:203)
HarpoonLauncher.FixedUpdate () (at Assets/Scripts/HarpoonLauncher.cs:60)
However the rope length still seems to change! So what am I doing wrong here?
|
|
|
Access ObiEmitter class in C# |
Posted by: fluidman84 - 20-06-2020, 04:19 AM - Forum: Obi Fluid
- Replies (2)
|
 |
I'm sure that there is a easy answer to this, but I've looked all over for the correct namespace to gain access to the speed property on a ObiEmitter component. In the docs I only see Obi.ObiActor referenced, but my IDE only identifies Obi.ObiCharacter.
What am I missing to get access to ObiEmitter?
|
|
|
|