Arrow Shooting / Sticking

Here’s one way to make arrows stick in movable and rotatable targets, including enemies:

Left Click to shoot arrows

I was feeling a bit inspired after Topical’s help request on how to make arrows stick, and this is the result after some testing…
Most of the “arrow sticking” math takes place in the bundle inside the Arrow object, the rest is just some physics manipulation to make the arrow impacts work somewhat realistically. A bit of unnecessary code in the enemy object (in the ‘Arrow Hits’ bundle) makes the enemies really fly far when they get hit by arrows. However, the arrow impacts with boxes just use the Flowlab engine’s default impact physics (which work due to the arrows being solid with high Density.)

Some issues/quirks of this method:
-Arrows are Emitted, so there is a limit to how many can be shot. Eventually you will run out of Emitted objects and the bow will stop shooting. I’ve made them expire after a while, but even then the bow will not shoot. I’ve tried having the arrows delete themselves after a certain amount of arrows are shot after them, and that doesn’t keep the bow from stopping shooting either. (Any ideas?)
-sometimes arrows will either be shot into inside an object or land inside an object which flips the arrow to a random direction.
-Arrow hitboxes are very small to make them not collide with the Player right when they are shot, so sometimes it looks like you are shooting through something when the arrow is just emitted behind / past the object.
-Arrows that land on the player kind of bug out since they are solid but not set to stick in the player object.
-Occasionally an arrow will hit something at such an angle that it looks like it is floating in the air, but will still stick to and move with the object.
-There is a bug or oddity with the Emit block that makes it rotate solid objects later when “Rotate Objects” is checked, so arrows will be flat for one frame when they are first shot
-Because Enemies can be rotated by arrow impacts and in general, they are a lot worse at jumping and following the Player, often resulting in them getting stuck.
-There isn’t yet a way for objects that get destroyed to delete the arrows attached to them.

Any feedback or criticism would be great.

7 Likes

I stuck so many arrows in him lol
image

4 Likes

Try setting the arrow to have a number, then have a global that acts like a trigger and goes off every time you shoot. Have that Global countdown the arrow number and delete the arrow when it hits 0.

If it were me, I would try arrow without being solid but still have a hitbox. And then use Parenting to hit objects you want the arrow to hit (or more specifically just not the player).

Yeah, this is a bug…

Another reason on trying to not use solid arrows. As well it would help for Arrows to overlap over a single target.


Overall really nice example, would be cool to look over the math and see ways on simplifying the bundles with expressions.

2 Likes

Is this not the same thing but at high FPS? This was the first thing that came to my mind for making sticky arrows. This doesn’t stick to moveable objects like yours, but I made it relativity quickly so I haven’t thought of the proper solution yet (I’ll probably try to find the distance from the wall to the contact point and then displace the arrow, accounting for angle as well). So if it’s bugged and not attaching to the wall properly it’s probably because I’m editing the code to try and make it work for a movable object as well.

(I have the arrow attachment as a 2nd object because it’s easier to work with that way, but I could condense it into 1 if needed)

2 Likes

This is so cool :star2::star2:
Thanks for sharing

4 Likes

Thank you for the feedback; so I tried that method for deleting arrows, and it deletes them properly, but it appears that the deleted arrows still count towards the maximum Emitted object amount even after they’re deleted…? Not sure if that’s true but whatever the case the arrows still stopped firing even after applying the limit (the limit was set to around 150 or so)
Regarding the arrows being solid, I originally was going to make them non-solid (and in fact they still work if you turn them non-solid), except for a few problems that that causes:

  1. The non-solid arrows will register their collision when already partway through a wall or box or whatever, and so they will stick out the other side or look like they’re stuck into the object just by the fletchings sometimes. Solid arrow physics solve this since Flowlab’s engine will register the collision and then back the arrow out until it’s not inside the other hitbox, so it usually looks like it’s stuck in by the arrowhead.
  2. The arrows won’t have any impact force if they aren’t solid, which means if you want impact force you have to make it manually. I actually made some code for proper transfer of force between the arrow and whatever it hits (you can see some of this in the box objects) but eventually I realized it still wasn’t going to be as good or accurate as just Flowlab’s default impact physics, since there isn’t yet a way to make rotational force a thing (not very practically, anyway).

But I see your point and really I think using non-solid arrows will probably be a better choice in the long run, it’s just going to take a bit more work.

2 Likes

Ha, yep there’s no way to kill enemies yet

1 Like

That’s a good example, certainly it’s a lot more simplified and clean than mine, and indeed it runs more smoothly (the frame rate drop in mine comes from the pathfinding for the enemies, not as much the arrow logic).
I do notice your code would probably only work for if there’s one bow shooting arrows, since it uses a general message to all arrows, and that would start to overlap if there were multiple bows shooting.
But nice work, and I look forward to seeing your progress here.

1 Like

Thank you, and hopefully with it being shared people can improve on it

1 Like

I found out if you go to emitter, you can choose how many times it shoots before not shooting

Welcome to flowlab! What are you referring to here? Which emitter?

2 Likes

Thx. I am referring to, I saw people have troubles with their guns not stopping shooting. All I have trouble with is, how do you make an inventory?

Oh, ok then.
There are lots of good inventory examples out there, like these:

Try just searching “inventory” in the forum’s search bar (the magnifying glass in the top right of the screen).
Usually it can also help to make your own help request if you can’t find the answer for your specific situation.

1 Like

Thank you. Beside’s I am new here. can you help me with the ropes?

1 Like

Welcome, Docterfun to the forums!

I think I first replied to you asking not to revive dead topics, in some other topic.

Anyway, there’s a rope example somewhere made by this user… I kinda forgot where it was though. But if you need more help you could start a new topic which might get some user’s attention.

Ok, bye.

1 Like

Try the 3rd level of this:

(But it would be really nice to try and keep things on topic here—this thread is originally about arrow shooting/sticking mechanics)

3 Likes

Ok. I wil try 2 stay on topic, I’ve only been using Flowlab 4 6 wweeks now.

3 Likes