Quantcast
Channel: Questions in topic: "rotating"
Viewing all articles
Browse latest Browse all 173

Jump perpendicular/adjacent to current point on a rotating circle

$
0
0
Hello! So I have a box that becomes a child of a rotating circle on collide and I am adding a fixed joint to the point of collision so that the box will seem to be rotating on the surface of the circle (not sure if this is the best way to achieve that) Now I want the box to jump perpendicular to the point it is currently at when I click (jump down if it is at the bottom, left if it is on the left side..etc). Or adjacent to the surface if that is possible as well. I tried to do so by adding to the circle (the parent) a surface effector, then when I click I detach the box from the parent and remove the fixed joint but it doesn't work well and it is buggy. this is the parent object: void Update() { transform.Rotate(new Vector3(0f, 0f, -100f) * Time.deltaTime); } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "Box") { collision.transform.parent = transform; } } And this is the Box: private void Update() { if (Input.GetMouseButtonDown(0) && hasJoint) { FixedJoint2D fixedJoint = gameObject.GetComponent(); Destroy(fixedJoint); gameObject.transform.parent = null; hasJoint = false; } } private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.GetComponent() != null && !hasJoint) { gameObject.AddComponent(); gameObject.GetComponent().connectedBody = collision.rigidbody; hasJoint = true; } } I am new to Unity/C# and I would appreciate some help! Thank you! ,I have an object (box collider 2D) that becomes a child of a rotating circle when it touches it, I add a fixed joint at that point so it will rotate with it (not sure if that is the best way to do it). When I click, I want the object to jump perpendicular to the surface at the current time (if it is on the bottom of the circle jump down, if it is on left side jump left etc..). I tried using the circle (the parent) as a Surface effector and then detaching it and removing the fixed joint on click but it does not look good and buggy. Any suggestions? thank you so much!

Viewing all articles
Browse latest Browse all 173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>