Hello! I’m an extreme amateur and this has been giving me a heck of a time. When the player is on the ground (2D), I want an arrow to spawn and rotate around the player in a ~150 degree arc. So far I have been able to instantiate an object at the correct position, but I can’t figure out the rotation. One of the main issues I’m having is that I need to check if the player is touching the ground in the Update method, but my if statement using a bool (so that I don’t instantiate countless objects) ends before any movement can happen. Thanks in advance!
Welcome!
First thing I wanna point out is that screenshots of code are not super-useful. Instead, please use code tags:
How to use code tags: https://discussions.unity.com/t/481379
For your problem, I suggest this approach:
-
either spawn or emplace the arrow in the scene always
-
give the player a reference to that arrow GameObject
-
have the player control it: when on ground, enable it, when jumping, disable it
-
finally turn the arrow the way you want. This part I don’t quite understand what you want with the whole 150-degree arc thing.
To further explain what you want, could you maybe scribble a drawing?
Thanks for all the pointers! I’ll try your approach next! I slaved away in MS paint for 3 minutes to help illustrate what I want to do. I’ve got a little slime character and he sticks to surfaces when he touches them (I got that part down). When he’s touching a surface, I want the arrow to spawn/enable and then rotate back and forth in an arc using the slime as the pivot point. I want the slime to jump in whatever direction the arrow was pointing at the time jump was pressed. From all my searching I think transform.RotateAround and Mathf.PingPong will be key, but I don’t know how to properly implement them.
And that tells me what you’re doing! So it’s like a golf game, where the arrow sways, and you go BAP when you think it’s right and Mr Slime goes flying.
Here’s how, in pseudocode steps because it sounds like you’re pretty sharp with what’s going on here:
First, make or modify your GameObject hierarchy: make slime, make arrow, but hang the arrow a little bit below him hierarchy wise, like so:
ArrowPivot
VisibleArrowSpriteOffsetAwayFromAbove```
Now, for the script.
- have a float ```myLocalTime``` that steadily advances with time:
myLocalTime += Time.deltaTime; // put this in Update()
To compute the angle, do something like this:
// this gets us a cycling fraction from 0.0 to 1.0 over the RateOfBackAndForth time interval
float angle = Mathf.PingPong( myLocalTime, RateOfBackAndForth) / RateOfBackAndForth;
// this scales it up
angle *= 150.0f;
To drive the angle out to the arrow, do something like this:
ArrowPivotTransform.localRotation = Quaternion.Euler( 0, 0, angle);
NOW! FOR THE TAP!
if (TAPPED)
{
// this vector should be whatever your “natural” arrow orientation is, probably up?
Vector3 arrowUp = Vector3.up;
// tilt it by the angle computed above
arrowUp = Quaternion.Euler( 0, 0, angle) * arrowUp;
// TODO: send Mr Slime Blob flying in this direction, probably scaled up by the force or velocity you want
}
And obviously, hide/show the arrow (and disable/enable the jump feature) based on sensing the ground or not.
There's a lot above, hit me if any Q or if I left anything mysterious.
From an architectural standpoint you could make this a separate script, put it on that pivot.
That way it would have a reference back to the root Rigidbody to send it flying.
And the main blob ground sensing controller would have reference to the pivot to just turn the entire GameObject hierarchy off, which would hide the arrow, stop the swaying count, and disable all the above leap mechanism, until you were grounded again.
Dude. You’re a beast. Thank you so much! I’ve seen you answering questions while scouring the forums previously, so as far as I’m concerned you’re a local legend. I’m excited to give this all a shot, and I’ll update this thread if I succeed. Have a good one!

