- Home /
Question by
Rostislavvacek116 · Jan 12, 2021 at 11:59 AM ·
2d rotation
Trying to rotate my character slower (2D)
How ? My code is this:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Movement : MonoBehaviour { public float speed = 2.5f; private float hI; private Rigidbody2D rb; public bool jeNaZemi = true; private bool vPravo = true;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
hI = Input.GetAxis("Horizontal");
transform.Translate(Vector3.right * hI * speed * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && jeNaZemi)
{
rb.AddForce(Vector3.up * 30, ForceMode2D.Impulse);
jeNaZemi = false;
}
if(vPravo == false && hI > 0)
{
Pretocit();
} else if(vPravo == true && hI < 0)
{
Pretocit();
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
jeNaZemi = true;
}
void Pretocit()
{
vPravo = !vPravo;
Vector3 Scaler = transform.localScale;
Scaler.x *= -1;
transform.localScale = Scaler;
}
}
Comment
Answer by logicandchaos · Jan 12, 2021 at 12:19 PM
You will probably have to create a coroutine to do this. Check the documentation in it.
Absolutely don´t understand it.... I am a beginner... Isn´t there any other way to do it ? animation ?
you can use the animator to animate variables as well, but learning coroutines will help in the long run.