Hello again!
https://www.youtube.com/watch?v=Gqkz-JlseRw
I created this pendulum, found that script on the net and refactored it to obi rope.
By the way it looks like very weird. How can I create a more nicer look?
script is here:
public class ObiRopePendulum : MonoBehaviour
{
[Range(0.3f, 10)] public float moveSpeed = 0.8f;
[Range(5f, 40)] public float angleScale = 20f;
private float _leftAngle = -10;
private float _rightAngle = 10;
private bool _clockwise;
private CreateObiRope _createObiRope;
private void Start()
{
_createObiRope = GetComponent<CreateObiRope>();
_clockwise = true;
_rightAngle = moveSpeed * angleScale;
_leftAngle = -_rightAngle;
}
private void Update() => Move();
private void Move()
{
var angle = _createObiRope.GetSignedRopeAngle();
if (angle > _rightAngle)
_clockwise = false;
if (angle < _leftAngle)
_clockwise = true;
var speed = !_clockwise ? moveSpeed : -moveSpeed;
var v = new Vector3(speed, 0, 0);
_createObiRope.PendulumVelocity(v);
}
}
and the PendulumVelocity:
public void PendulumVelocity(Vector3 velocity)
{
/*
var lpIndex1 = GetFirstParticleIndex();
var lpIndex2 = GetLastParticleIndex();
for (var i = lpIndex1; i <= lpIndex2; i++)
{
rope.solver.velocities[i] = velocity.ToVector4();
[/i][i] }*/
rope.solver.velocities[GetLastParticleIndex()] = velocity.ToVector4();
}[/i]
I want the lamp swinging always left/right but with a physics correct way.
How can I improve it to a better way? It is now not so good at the moment
https://www.youtube.com/watch?v=Gqkz-JlseRw
I created this pendulum, found that script on the net and refactored it to obi rope.
By the way it looks like very weird. How can I create a more nicer look?
script is here:
public class ObiRopePendulum : MonoBehaviour
{
[Range(0.3f, 10)] public float moveSpeed = 0.8f;
[Range(5f, 40)] public float angleScale = 20f;
private float _leftAngle = -10;
private float _rightAngle = 10;
private bool _clockwise;
private CreateObiRope _createObiRope;
private void Start()
{
_createObiRope = GetComponent<CreateObiRope>();
_clockwise = true;
_rightAngle = moveSpeed * angleScale;
_leftAngle = -_rightAngle;
}
private void Update() => Move();
private void Move()
{
var angle = _createObiRope.GetSignedRopeAngle();
if (angle > _rightAngle)
_clockwise = false;
if (angle < _leftAngle)
_clockwise = true;
var speed = !_clockwise ? moveSpeed : -moveSpeed;
var v = new Vector3(speed, 0, 0);
_createObiRope.PendulumVelocity(v);
}
}
and the PendulumVelocity:
public void PendulumVelocity(Vector3 velocity)
{
/*
var lpIndex1 = GetFirstParticleIndex();
var lpIndex2 = GetLastParticleIndex();
for (var i = lpIndex1; i <= lpIndex2; i++)
{
rope.solver.velocities[i] = velocity.ToVector4();
[/i][i] }*/
rope.solver.velocities[GetLastParticleIndex()] = velocity.ToVector4();
}[/i]
I want the lamp swinging always left/right but with a physics correct way.
How can I improve it to a better way? It is now not so good at the moment