15-05-2018, 07:57 PM
If i change the simulation order off of Fixed Update it will snap properly but need it to interact with other physic objects properly.
Any advice?
(15-05-2018, 08:02 PM)cubrman Wrote: [ -> ]Hey what software did u use to record the video? When I try using OBS studio the cloth plugin starts bugging out (cloth behaives like a bunch of spiky triangles).
(15-05-2018, 07:57 PM)VirtualCucumber Wrote: [ -> ]
If i change the simulation order off of Fixed Update it will snap properly but need it to interact with other physic objects properly.
Any advice?
(16-05-2018, 12:02 PM)josemendez Wrote: [ -> ]Use "After Fixed Update" as your simulation order, if the object is moved using animation.
If you're not using animation but procedural movement in Update(), do it in FixedUpdate() instead.
public void FixedUpdate()
{
Move();
}
private void Move()
{
targetVelocity = canMove ? input * moveSpeed : Vector2.zero;
float targetXAccelerationTime = input.x == 0 ? decelerationTime : accelerationTime;
float targetYAccelerationTime = input.y == 0 ? decelerationTime : accelerationTime;
velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocity.x, ref velocityXSmoothing, targetXAccelerationTime);
velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocity.y, ref velocityYSmoothing, targetYAccelerationTime);
rb.velocity = velocity;
transform.rotation = Quaternion.Euler(0, 0, velocity.x * torque);
}
(16-05-2018, 01:59 PM)VirtualCucumber Wrote: [ -> ]My movement is in FixedUpdate()
Code:public void FixedUpdate()
{
Move();
}
private void Move()
{
targetVelocity = canMove ? input * moveSpeed : Vector2.zero;
float targetXAccelerationTime = input.x == 0 ? decelerationTime : accelerationTime;
float targetYAccelerationTime = input.y == 0 ? decelerationTime : accelerationTime;
velocity.x = Mathf.SmoothDamp(velocity.x, targetVelocity.x, ref velocityXSmoothing, targetXAccelerationTime);
velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocity.y, ref velocityYSmoothing, targetYAccelerationTime);
rb.velocity = velocity;
transform.rotation = Quaternion.Euler(0, 0, velocity.x * torque);
}
This is my movement, simply using Rigidbody velocity.
EDIT:
I could easily Translate the object instead, just wanted to keep it simple with a small project.
(16-05-2018, 02:11 PM)josemendez Wrote: [ -> ]In Unity, the order of events is the following:
- FixedUpdate (0, 1, or more times)
- Animation update
- WaitForFixedUpdate (After Fixed Update in Obi)
- Update (just once)
So if you are moving the object in Fixed Update(), setting the solver update order to "After Late Update" should ensure simulation happens after the object has been translated.
Edit: Also, ObiSolver exposes lots of C# events that are called at particular times during the simulation loop. OnStepBegin, OnStepEnd, OnBeforePositionInterpolation,OnFixedParticlesUpdated... etc. You could insert your code in a delegate to be called during OnStepBegin, which is triggered every FixedUpdate just before starting the simulation step. This way you could still use Fixed Update simulation order.
private void Start()
{
solver.OnStepBegin += Move;
}
(16-05-2018, 04:05 PM)VirtualCucumber Wrote: [ -> ]I had it simulate after fixed update at first but when i started pinning physics objects to it, the objects would not react.
(16-05-2018, 04:05 PM)VirtualCucumber Wrote: [ -> ]And I would assign that function to the event like this?
Code:private void Start()
{
solver.OnStepBegin += Move;
}
(16-05-2018, 04:32 PM)josemendez Wrote: [ -> ]Yes, as the rope is being simulated after regular physics, so rigidbodies will ignore the rope. You should use OnStepBegin then, to make sure the order in which things happen each FixedUpdate() is this:
- The object moves (your Move() function is called)
- The rope is simulated.
- Rigidbodies are simulated.
Yes, but make sure the function parameters match the delegate parameters.
private void Start()
{
solver.OnStepBegin += Move;
}
public void Move(object sender, EventArgs e)
(16-05-2018, 05:06 PM)VirtualCucumber Wrote: [ -> ]Thanks for the info.
Sorry for spamming with questions but i havent dealt yet with Delegates and Events. I get the jist of them just havent used them.
I cant just have:
Code:private void Start()
{
solver.OnStepBegin += Move;
}
public void Move(object sender, EventArgs e)
Do i have to declare a delegate in the ObiSolver class and assign its type to OnFrameBegin/End ?