- Home /
Rigidbody2d physic movement on 2d terrain.
I would like to move my AI tank on 2d terrain. 2D terrain is not always straight it has a hills. When I just start move my AI tank if it is collides with hill (or tries to climbs to the hill), AI tank starts spin(rotates) on Z axis. I'm moving left/right on x axis. during spinning or during rotating on Z axis if I put 0 on Z axis manually in Inspector, tank moves normally when it collides with next hill. I use 2d capsule collider as a wheel. I tried everything but I can't get normal movement. I can't freeze Z axis completely cause I need Z axis a little bit when tank climbs to the hill.
private void FixedUpdate()
{
if (move)
{
// rig2D.MovePosition(rig2D.transform.position
+ (transform.right * vJoystick.y * Time.deltaTime * 3)
// + (transform.right * vJoystick.x * Time.deltaTime * 3));
//rig2D.velocity = new Vector2(-transform.position.x * 5 * Time.fixedDeltaTime, rig2D.velocity.y);
//Vector3 dir = (target.transform.position - transform.position).normalized;
//dir.z = 0;
//rig2D.MovePosition(transform.position
+ dir * 2 * Time.fixedDeltaTime);
//transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, Vector3.zero, Time.deltaTime);
//transform.position = Vector3.Lerp(transform.position, target.transform.position, Time.deltaTime);
// float timeSinceStarted = Time.time -
_timeStartLerping;
// float presentageComplete = timeSinceStarted / timeTakenDuringLerp;
// transform.position = Vector3.Lerp(_startPos, _endPos, presentageComplete);
// if(presentageComplete >= 1.0f)
// {
// move = false;
// }
}
}
Do I need freeze Z axis and rotate it with clamp limit?
Your answer
Follow this Question
Related Questions
How to keep the velocity of a rigidbody2d while changing its direction according to rotation? 1 Answer
setting transform physics2d issue 0 Answers
2D rigidbody velocity relative to rotation? 0 Answers
In unity 2D c# how to rotate an object like geometry dash? 1 Answer
Arm passing through objects (Rotation - Rigidbody2D) 0 Answers