2D z rotation in specific angel / launching object
Helly Guys,
little disclaimer here im a total noob and i'm sorry if my attempt and code are completly bs.
I want a flat sprite (just like a block) to launch an object on top of it in to the air. For this I setted up a HingeJoint2D with a limited angle. It should work like so: the default position of the sprite is an angle of 0 degrees. when I press the ArrowDown key it slowly rotates down on the z axis. As soon as I leave the ArrowDown key the Sprite snaps upwards into his default position and launches off the object on top of it.
It seemed pretty doable for me but i'm pretty stuck and really cant find a solution on the internet. Would appreciate any tips and general tips on this - thanks!
This is what I got:
public float speed = -100f;
// Use this for initialization
void Start() {
HingeJoint2D hinge = GetComponent<HingeJoint2D>();
bool enabled = new bool();
hinge.useMotor = enabled;
}
// Update is called once per frame
void Update() {
if (Input.GetKey(KeyCode.DownArrow)) {
transform.Rotate(0, 0, speed * Time.deltaTime);
enabled = false;
}
}
Your answer
Follow this Question
Related Questions
Parenting an object causes it to change rotation 1 Answer
Sprites only rotate by 90 degrees 0 Answers
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
2D Sprite issue when rotating towards mouse click location. 2 Answers