Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling and enabling the motor (with a rigidbody attached to) on a ramp makes the motor move permanently #70

Open
h-shokri opened this issue Jul 2, 2017 · 0 comments

Comments

@h-shokri
Copy link

h-shokri commented Jul 2, 2017

When we disable the PlatformerMotor2D to handle the physics by the Rigidbody2D and then again enable the PlatformerMotor2D to gain the control of the character, the rigidbody velocity should be zeroed otherwise the character will tend to move around using the previous velocity.
I have inserted a line of code in PlatformerMotor2D.OnEnable() and that solves my problem:

private void OnEnable()
{
        if (_rigidbody2D != null)
        {
	        _velocity = _rigidbody2D.velocity;
		_rigidbody2D.velocity = Vector2.zero; //I have added this to solve the problem.
                _originalKinematic = _rigidbody2D.isKinematic;
                _rigidbody2D.isKinematic = true;
        }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant