Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to make the Start/End Prefab able to be Raycasted?
#14
(03-11-2017, 03:49 PM)Rexima Wrote: Thank you very much, it works now.

I have an another question, is it possible to rotate the Start or End Prefab, when its added to an Pin Constraint?
I want to use this rope asset to connect various machines together.
And when i fix the Start or End prefab, it hangs, but i want that its more stiff and looks like its real connected to the machine.

Is it also possible to get some informations, if the rope is stretched?
I want to change the length of it, when the character is moving and the rope is stretched.
I also need to know it, because if the rope is stretched and the max length is exceeded, the player should drop the rope.
Btw. where do i set the max length of the rope? - Pooled Particles

When the length of the rope was changed, than UsedParticles doesnt work anymore to get the last particle (End prefab)

Sorry for this amount of questions, but i can't find any answer on the wiki/forum

Hi!

Fixing/pinning the last 2 particles instead of just the last one will allow orientation to kick in. (1 point in space does not define a direction/orientation, 2 points however do). Similarly, fixing the first two particles instead of the first one works in the same way for the start of the rope.

When changing the length of the rope, UsedParticles should still give you the total amount of particles in the rope. However, If your ObiRopeCursor is not at the end (for example it is in the middle, or at the start of the rope) then the "new" particles generated when increasing its length will be added in the middle of the rope, so UsedParticles-1 will no longer be the last one in the rope (but the most recently added one, close to the cursor).

In this case, the best way is to use  GetConstraintIndexAtNormalizedCoordinate(). This will return the index of the distance constraint at a given point in the rope (0 is the start, 1 is the end, any value in between is a percentage).

Then you can use the constraint index to get the two particles joined by it.


Code:
int constraint = rope.GetConstraintIndexAtNormalizedCoordinate(1); //get last constraint in the rope (use 0 for first one)

ObiDistanceConstraintBatch distanceBatch = rope.DistanceConstraints.GetBatches()[0] as ObiDistanceConstraintBatch;

// get the last two particles in the rope:
int lastParticle = distanceBatch.springIndices[constraint*2+1];
int prevParticle = distanceBatch.springIndices[constraint*2];

PD: As a side note, you can enforce a maximum rope length yourself if you wish too. No need to rely on the amount of pooled particles. Simply check rope.RestLength and no longer call ChangeLength() if the rope is too long (or too short). RestLength is not affected by stretching or compressing the rope, it reflects the actual "logical" length of the rope, not the apparent one.
Reply


Messages In This Thread
RE: How to make the Start/End Prefab able to be Raycasted? - by josemendez - 04-11-2017, 10:25 AM