Answer the question
In order to leave comments, you need to log in
Cell movement with RigidBody?
Good afternoon!
It is necessary that the character moves through the cells and physics is not violated.
That is, they pressed the button to the right, he moved 1 cell to the right.
If he ran into something, he did not move.
Whether he can push the object or rest against it is decided by physics itself.
If you move an object through a transform, then physics does not work.
If you manually lock the buttons when moving and check if the player has reached the next cell, then when he rests, the buttons will not unlock.
Does anyone know a suitable way?
Answer the question
In order to leave comments, you need to log in
Did it in the end
private IEnumerator Move(Axis axis, int point)
{
var direction = Vector3.zero;
direction[(int) axis] = point;
_move = true;
if (Physics.RaycastAll(transform.position, direction, 2f).Length > 1)
{
_move = false;
yield break;
}
_finishPosition = transform.position + direction;
_timer = 0;
_curve = new AnimationCurve();
_curve.AddKey(0f, transform.position[(int) axis]);
_curve.AddKey(_speedMove, _finishPosition[(int) axis]);
while (true)
{
_tmpPosition = transform.position;
_tmpPosition[(int) axis] = _curve.Evaluate(_timer);
_rb.MovePosition(_tmpPosition);
if (transform.position == _finishPosition)
{
_move = false;
yield break;
}
_timer += Time.fixedDeltaTime;
yield return new WaitForFixedUpdate();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question