Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rest all state
#4
(04-02-2019, 09:52 AM)_gaoyu_ Wrote: I try to rest prevPositions, but no change

Hi there,

I'm assuming you want to teleport the object to a new position, right? In that case, you cannot set all particles to the same position. This will result in the object collapsing to a single point, then "exploding" after moving to the new location and gaining momentum in a random direction. You need to calculate their position relative to the transform prior to teleporting, then adding these delta positions to the new object position. Something like this:

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;

public class Teleport : MonoBehaviour {

    public ObiSoftbody actor;

    void Update () {

        if (Input.GetKeyDown(KeyCode.A)){

            Vector3 newPosition = new Vector3(Random.Range(-4.0f,4.0f),1.5f,Random.Range(-4.0f,4.0f));

            for (int i = 0; i < actor.particleIndices.Length; ++i){
                int pId = actor.particleIndices[i];
                actor.Solver.prevPositions[pId] = actor.Solver.positions[pId] = ((Vector3)actor.Solver.positions[pId] - actor.transform.position) + newPosition;
                actor.Solver.velocities[pId] = Vector3.zero;
            }

                  actor.transform.position = newPosition;
        }
    }

}
Reply


Messages In This Thread
How to rest all state - by _gaoyu_ - 02-02-2019, 02:33 PM
RE: How to rest all state - by josemendez - 03-02-2019, 02:13 PM
RE: How to rest all state - by _gaoyu_ - 04-02-2019, 09:52 AM
RE: How to rest all state - by josemendez - 04-02-2019, 04:08 PM
RE: How to rest all state - by _gaoyu_ - 05-02-2019, 06:13 AM
RE: How to rest all state - by josemendez - 05-02-2019, 08:57 AM
RE: How to rest all state - by _gaoyu_ - 05-02-2019, 10:18 AM
RE: How to rest all state - by josemendez - 05-02-2019, 10:35 AM
RE: How to rest all state - by _gaoyu_ - 05-02-2019, 10:46 AM