- Home /
Velocity Movement & Physics Interactions by Rigidbody2D
I'm creating a platformer game at this time. The best movement system I've found for the player is by direct manipulation of the velocity. However, this poses a problem. Whenever a physics interaction occurs, my code will simply overwrite it on the x axis. That is not the desired effect. I'm wondering if anyone has any ideas as to how to maintain the velocity controlled movement system, as well as allow for physics reactions to coexist.
I'm open to other movement systems that may work as well as this one. The control you get through direct velocity control is something I would hate to lose.
protected void SetVelocity()
{
float curSpeed;
curSpeed = 100f * Time.deltaTime * speed * Mathf.Asin(theta);
GetComponent<Rigidbody2D>().velocity = new Vector2(curSpeed, GetComponent<Rigidbody2D>().velocity.y);
}
the line 5 could be
GetComponent<Rigidbody2D>().position += new Vector2(curSpeed, GetComponent<Rigidbody2D>().velocity.y) * Time.deltaTime;
difference between assigning to transform.position and assigning to rigidbody2D.position is that rigidbody considers the colliders around itself before moving while transform does vice versa causing twerking and stuff (twerking is the best word I could come up with, me no nativ inglish speeker)
Your answer
Follow this Question
Related Questions
AddForce vs Velocity issues with Rigidbody2D 2 Answers
Inconsistent Rigidbody2D velocity. 0 Answers
2D 360 degress platformer example needed 0 Answers
How to make Rigidbody.AddForce less delayed in Unity3D? 0 Answers
Throwing knife doesn't throw correctly 0 Answers