Make a tongue come from a frogs mouth to a target

Hi,
I’m wondering if there’s a better method to have a tongue come from a sprites’s mouth to a target.

Currently I’m able to do it by not using trigger once, so the tongue grows from the mouth infinitely to the target. Everything works fine except I’m sure it makes things like contact with something other than the player awkward or not function properly.

Basically picture a frog shooting out it’s tongue when it sees a target. Sometimes the player already moved and the tongue hits something else before or at the target.

Is it possible to have the tongue create, then extend towards the target. I’ve been using tweens and it looked cool but I’m sure there’s a better way!

I messed around with a panel sprite and stretched one side, but couldn’t get that to do all 4 directions without a lot of mess…

Thanks for any suggestions :slight_smile:

Edit - I’ve found that the panel sprite tongue can be used if i use change width add “tongue. Distance. Player” - correct?

My first idea would be reverse health bar formula (well maybe not reversed but not using health but distance instead)
Most suggest/used method of making health bar is adjusting its width with formula
So how about using exact same thing for adjusting length of tongue?

This is formula for health bar width based on HP
BarWidth/ObjectMaxHealth*ObjectCurrentHealth

So how about
TongueSpriteWidth/TongueMaxLenght*DistanceBetweenFrogMouthAndTarget

Where TongueMaxLenght would indicate how long tongue can get in your game

1 Like

Nice one! that makes sense, thank you I’ll go have a mess around with that too :slight_smile:

Now that i think of it maybe that formula is wrong
Maybe simply distance between frog mouth and target is enough alone to set to width of tongue to make it work

I messed around in the past with a grappling hook like from Zelda. I used the same principle as the basis for this. I ended up rewriting it. Use as much or as little as you want to. The timing might need some work or maybe a lot of work. The nice thing is the togue target remains fixed even if the player moves.

project:

The point used for the mouth needs work. it should take into account the size of the tongue and the angle. think of the mouth as a circle. you need to center that circle on the point but it changes based on the direction of the tongue. At its basic, the offset from the point would be minus half the height of the mouth or circle. Right now, it’s placing the top-left corner of the mouth at the mouth point on the player.

It’s late and my brain can’t get that value. I believe it’s a position like 16 pixels from the mouth point on the player in the opposite direction of the tongue.

1 Like

The idea is fine and helpful, the only issue is making it stretch in the other 3 directions. Some really weird stuff happens when you try to rotate then apply lol

Do you think I’m correct in trying to use a panel sprite? It’s just that the centering of it isn’t obvious. Someone else posted a complicated answer which could be fun to try when my brain isnt feeling like mush :stuck_out_tongue:

Thanks for this.
Do you think it is applicable to a 4 direction only tongue (think grid based and it can go 0,90,180,270 degrees)

I’m tempted to up my game and understand that variable method, but not sure if it’s overkill for my simple thing. Is that a panel sprite being used?
(I can see how the centering issue is quite a ball ache! Since I’m using only a basic extend by increments of the distance to target…but that gets very weird if any rotation happens before movement.)

It is a panel sprite. I like how it maintains the texture and tip. IDK if it would be the best way to do your project. It might be overkill even though it’s pretty light on code. It’s a concept. If not for this one then maybe for the future for you or someone else.

IDK if 0-360 will work
But for sure for rotating stuff 0 to 180 and -180 to 0 works

Which is
image

Under blue button on top you have angle of crosshair to player
So it would be easier to determine angle you are looking for

I went back to using a sprite and adjusted the centre to the edge, which lets me tween the width or just change the width + angles work fine that way too.

The only thing is the tongue only makes it to target if i multiply by 2 to the formula - I think im using the wrong one (tween width to tongue.distancetoposition(target) - i also tried just using distance)