Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Animating rod rest position
#21
The first frame of the simulation starts at the blueprint rest position, which is different from the new torsion position. So theres a jump at the start as they get into position. 

So i need a way to change that rest position before the simulation starts so the particles start in the position we want.
Reply
#22
(23-05-2021, 04:27 AM)Hakazaba Wrote: The first frame of the simulation starts at the blueprint rest position, which is different from the new torsion position. So theres a jump at the start as they get into position. 

So i need a way to change that rest position before the simulation starts so the particles start in the position we want.

Try subscribing to actor.OnBlueprintLoaded, and updating the rest position there. That will be called immediately after loading the blueprint, and before simulation starts.
Reply
#23
Im sorry to ask for this, but im not very familiar with events. How would i write a subscription to that event which triggers a function?
Reply
#24
(31-05-2021, 06:53 AM)Hakazaba Wrote: Im sorry to ask for this, but im not very familiar with events. How would i write a subscription to that event which triggers a function?

Code:
//somewhere in your code (Start, Awake, OnEnable...) you subscribe to OnCollision:
solver.OnCollision += MyMethod;

//somewhere else (OnDisable, OnDestroy...), you unsubscribe:
solver.OnCollision -= MyMethod;

// the method being subscribed:
void MyMethod (object sender, Obi.ObiSolver.ObiCollisionEventArgs e)
{
}

See:
https://docs.microsoft.com/en-us/dotnet/...rom-events
Reply
#25
Code:
    void SetStartPos(object sender, ObiActor.ActorBlueprintCallback e){
        print("Event triggered");
    }
    private void OnEnable() {
        rod.OnBlueprintLoaded += SetStartPos;
    }
    private void OnDisable() {
        rod.OnBlueprintLoaded -= SetStartPos;
    }
On each onblueprint loaded: No overload for 'SetStartPos' matches delegate 'ObiActor.ActorBlueprintCallback' 

rod is an ObiRod Actor
Reply
#26
This is because the signature of the SetStartPos function doesn't match the signature of the event delegate. When you subscribe a function to an event, the number and type of the parameters must match. Otherwise, how would the "output" of the event be passed as "input" to your function?

declare SetStartPos as:

Quote:void SetStartPos(ObiActor actor, ObiActorBlueprint blueprint)
{
print("Event triggered");
}
Reply
#27
Ok, modifying the rest darboux vectors on that event still does not make the simulation start from the position we want.
Reply
#28
(02-06-2021, 05:55 AM)Hakazaba Wrote: Ok, modifying the rest darboux vectors on that event still does not make the simulation start from the position we want.

Are you modifying the particle positions/orientations as well? the darboux vectors only set a "target" shape, the current shape of the rod is determined by particles. In a regular blueprint, the darboux vectors are calculated from the starting positions/orientations, so both the starting shape and the target shape are the same.
Reply
#29
Where exactly should i be setting position and orientation? The values i keep finding only have a get
Reply
#30
(10-06-2021, 11:38 AM)Hakazaba Wrote: Where exactly should i be setting position and orientation? The values i keep finding only have a get

You get/set positions and orientations by reading from/writing to an array. Check the manual:
http://obi.virtualmethodstudio.com/tutor...icles.html

for instance, to set the position of the first particle in a solver to zero:
Code:
solver.positions[0] = Vector3.zero;

to get it:
Code:
var pos = solver.positions[0];

Same for orientations, velocities, mass, radius, etc. All data in Obi is expressed in the solver's local space, the data you get is solver space, and the data you set is expected to be solver space.

actor.GetParticlePosition() and GetParticleOrientation() (which I guess are the ones you found) are just helper methods that retrieve world space values for convenience. They're quite slow though, it's best to access the data directly.
Reply