Making an object orbit another

Okay, I have a sword object (currently a placeholder). I have the orbit one object around another object extension. It doesn’t work. Or I don’t understand how it works (I really don’t) and am using it wrong. When I right click on the enemy, my sword just barely flicks, like it’s glitching, before returning to the exact same place it was already at. What is supposed to happen is that the player instantly pathfinds to the enemy when the enemy is right-clicked, and the sword then completes a single orbit, just as visual feedback, really, before instantly returning to its sitting point, where it stays as long as it is not orbiting.

If that sword does not swing, it’s like that scene in Doctor Strange, where he’s battling a dude in the ghost realm, and all the viewer can see is stuff arbitrarily crashing around them. There will be the RNG that decides if instantly killing the enemy is successful or not shown in the corner, and if it is, the enemy will seemingly arbitrarily vanish, but that’s not a good enough indicator here.

Do you want the rotation to look like it’s going in and out of the screen and in front and behind the player?

You don’t want to use Y-sort for that, but instead look at tweening an object variable or using a trigonometrical calculation to determine the z-order relative to the player’s z-order.

True. How about this: If weapon y is more than hinge (my central swinging object that is stuck at around the player’s waist) than hinge y, then weapon z order is player z -1, but if it is less than hinge y, then at player z +1, so that it will always swing in the same manner, around the player. It took me a bit to think of this but I think it would work.

1 Like

You could try using a combination of tween behavior and trigonometry. Use sine and cosine functions to calculate the position of the sword relative to the hinge, and adjust the z-order dynamically based on the y-position.