Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to rest all state
#1
I disable ObiActor and rest partcle position . wait 0.5 second , I enabled ObiActior ,but I found previous Acceleration still exist. Why?




code:

                GetComponent<ObiActor>().enabled = false;
                GetComponent<SkinnedMeshRenderer>().enabled = false;
                transform.position = new Vector3(Random.Range(-4.0f,4.0f),1.5f,Random.Range(-4.0f,4.0f));

                GetComponent<ObiActor>().Solver.positions[pId] = transform.position;
                GetComponent<ObiActor>().Solver.velocities[pId] = new Vector3(0.0f,0.0f,0.0f);

                yield return new WaitForSeconds(0.5f);

                GetComponent<ObiActor>().enabled = true;
                GetComponent<SkinnedMeshRenderer>().enabled = true;
Reply
#2
(02-02-2019, 02:33 PM)_gaoyu_ Wrote: I disable ObiActor and rest partcle position . wait 0.5 second , I enabled ObiActior ,but I found previous Acceleration still exist. Why?




code:

                GetComponent<ObiActor>().enabled = false;
                GetComponent<SkinnedMeshRenderer>().enabled = false;
                transform.position = new Vector3(Random.Range(-4.0f,4.0f),1.5f,Random.Range(-4.0f,4.0f));

                GetComponent<ObiActor>().Solver.positions[pId] = transform.position;
                GetComponent<ObiActor>().Solver.velocities[pId] = new Vector3(0.0f,0.0f,0.0f);

                yield return new WaitForSeconds(0.5f);

                GetComponent<ObiActor>().enabled = true;
                GetComponent<SkinnedMeshRenderer>().enabled = true;

Hi,

Also set prevPositions to the same as positions, since velocities are calculated using differentiation: new velocity = (position - previous_position) / delta_time.
Reply
#3
(03-02-2019, 02:13 PM)josemendez Wrote: Hi,

Also set prevPositions to the same as positions, since velocities are calculated using differentiation: new velocity = (position - previous_position) / delta_time.

I try to rest prevPositions, but no change
Reply
#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
#5
Hi josemendez,

I upload my test file and link: https://pan.baidu.com/s/1e8jU5dDUlEoZSLhKrK7VXg

I want to rest postion and Acceleration , but still failure. 

Every ball will rest pos when y<-5.0 ,but Velocity is error.   My idea is  ball will vertical fall  after rest;

You can check AddRandomVelocity.cs, KeyCode.Space can force balls.



Please

Thankyou
Reply
#6
(05-02-2019, 06:13 AM)_gaoyu_ Wrote: Hi josemendez,

I upload my test file and link: https://pan.baidu.com/s/1e8jU5dDUlEoZSLhKrK7VXg

I want to rest postion and Acceleration , but still failure. 

Every ball will rest pos when y<-5.0 ,but Velocity is error.   My idea is  ball will vertical fall  after rest;

You can check AddRandomVelocity.cs, KeyCode.Space can force balls.



Please

Thankyou

Hi,

Sorry, I'm unable to download the file you sent. The script I posted in my previous post will move the object to a random position, and it will of course fall due to gravity after being moved to a new position.

Make sure you have deactivated the AddRandomVelocity script in the ball pool scene (or at least commented out its original code), as that will set a random velocity for all soft bodies in the scene when you press "space".

Also, make sure "Simulate when invisible" is enabled in the ObiSolver settings. When disabled, the solver will cease to perform simulation once all objects are invisible to all game cameras.
Reply
#7
(05-02-2019, 08:57 AM)josemendez Wrote: Hi,

Sorry, I'm unable to download the file you sent. The script I posted in my previous post will move the object to a random position, and it will of course fall due to gravity after being moved to a new position.

Make sure you have deactivated the AddRandomVelocity script in the ball pool scene (or at least commented out its original code), as that will set a random velocity for all soft bodies in the scene when you press "space".

Also, make sure "Simulate when invisible" is enabled in the ObiSolver settings. When disabled, the solver will cease to perform simulation once all objects are invisible to all game cameras.

Hi,
Can you give me your email?
Reply
#8
(05-02-2019, 10:18 AM)_gaoyu_ Wrote: Hi,
Can you give me your email?

Yes, it's support(at)virtualmethodstudio.com or obi(at)virtualmethodstudio.com
Reply
#9
(05-02-2019, 10:35 AM)josemendez Wrote: Yes, it's support(at)virtualmethodstudio.com or obi(at)virtualmethodstudio.com

I send a mail to support@virtualmethodstudio.com
test file in mail
Reply