Monsters Get Up When Knocked Down in Unity 2D
You can use, to show the waking up process of zombies
C#
standup:
[SerializeField] float value=2f;
[SerializeField] private float m_inputZValue;
[SerializeField] private float m_tiltSpeed;
[SerializeField] float valueZ;
[SerializeField] bool fall;
Rigidbody2D rb;
void Start()
{
this.rb = GetComponent<Rigidbody2D>();
this.valueZ = this.rb.rotation;
}
void Update()
{
if(this.transform.rotation.z < 0 && this.fall==true)//fall on the right insland
{
if(this.value >=0)
{
this.value -= Time.deltaTime;
}
else
{
this.rb.isKinematic = true;
this.rb .rotation += this.m_inputZValue * this.m_tiltSpeed * Time.deltaTime;
}
}
else if(this.rb .rotation > 0 && this.fall==true )//fall on the left
{
if(this.value >=0)
{
this.value -= Time.deltaTime;
}
else
{
this.rb.isKinematic = true;
this.rb .rotation += -this.m_inputZValue * this.m_tiltSpeed * Time.deltaTime;
}
}
else
{
this.value =2f;
this.rb.isKinematic=false;
}
}
private void OnTriggerStay2D(Collider2D other)
{
if(other.CompareTag("insland") )
{
this.fall=true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if(other.CompareTag("insland") )
{
this.fall=false;
}
}
Post a Comment