Question by
traktorius81 · Dec 20, 2018 at 04:08 PM ·
2drotation
2d Saving rotation angle.,Saving 2d angle.
Hello, I just started learning unity and C#. I'm trying to make my ball fly, when i press space, but it doesnt event move, i would like to know how to improve this code and what is the problem. I think there is a problem with the facing angle Vector3, but how do I save it ? Thank you. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class saudymas : MonoBehaviour
{
public float greitis;
Vector3 zemyn;
public float saudymogreitis;
Rigidbody2D kamuolys;
bool isove = false;
// Start is called before the first frame update
void Start()
{
zemyn = new Vector3(0, 0, -greitis);
kamuolys = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
transform.Rotate(zemyn * Time.deltaTime);
if (Input.GetKeyDown(KeyCode.Space) && isove == false)
{
kamuolys.AddForce(zemyn * saudymogreitis);
isove = true;
}
}
if (Input.GetKey(KeyCode.S))
{
transform.Rotate(-zemyn * Time.deltaTime);
if(Input.GetKeyDown(KeyCode.Space) && isove==false)
{
kamuolys.AddForce(-zemyn * saudymogreitis);
isove = true;
}
}
}
}
P.S. sorry for my english.
Comment
Your answer
Follow this Question
Related Questions
2D TopDown rotating a gun according to its parent position, ON MOBILE, not PC, 0 Answers
Set Instanatiated Object's Rotation Towards Player 1 Answer
Parenting an object causes it to change rotation 1 Answer
Sprites only rotate by 90 degrees 0 Answers
Rotating multiple images continuously (2D) - Mobile performance/optimizations 2 Answers