Arrow Stickyness?

I’ve been thinking about how I want my bow/arrow dynamics to function in my game. So the idea is to have a relation between the angle of the impact and the toughness of a material (with some exceptions though).

This ofc has to be done in python but since I’m a wannabe python programmer… ok, ok I suck at it XD

Now what say the masters? :stuck_out_tongue:

PS: Maybe pushing me in the right direction is enough :smiley: Or you could make it, whatever works for you XP

Here goes nothing :F

Attachments


So I’m guessing that you want the arrow to sometimes just deflect off of the target and other times to stick?

I’m not going to do it for you, but consider that you’ll need to check a few things:
The velocity (including direction) of the arrow when it hits the target
Using getHitNormal(), the normal of the face that’s been hit.
Getting the hit object (with getHitObject() in 2.48 or objectHit in 2.49) and using hasattr(propname) to get what kind of material it is.

Then you can mess around with those to get something you like.

-Sam

This is a really interesting problem, and when I’m interested in things I tend to over analyze them, so prepare yourself for a wall of text. Basically, I am going to outline how I would go about solving this problem in theory, but I’ll let you do the actual coding.

I don’t know what you do or don’t know about vector math (I’m guessing probably more than me, but I’ll be writing as though you don’t know a lot- anything you already know you can just skip over anyway)

You can get the cos of the angle between 2 vectors by using the dot product- in this case you’ll want to compare the face normal and the velocity of the arrow. The closer the cos is to 1, the more parallel the arrow is to the surface. Depending on the density of the material, pick a cutoff value above which the arrow will reflect (it might be simple just to store material density as that cutoff, unless you need it in more real physical terms for something else)

You can get the hit normal by casting a ray along the velocity, using rayCast()- the third item returned is the normal.
If the normal is N, the velocity is V, and the length of Velocity is v, the dot product will be (NxVx+NyVy+Nz*Vz.)/v (normally you’d also divide by the length of the other vector too, but the normal is already length 1, or normalized)

Assuming the arrow is a rigid body and you just let the game engine control it, when the arrow reflects you can just let it do its thing (I doubt this is how you want to handle this tho, as the GE physics don’t do aerodynamics so the arrow won’t point the direction its flying- you can either manually orient the arrow along the velocity with python and let the ge physics take over from there, or what I usually do is to disable collision on the arrow entirely, and make myself some very simple physics using a ray cast in the velocity direction to test for collisions.
This is because we can assume that during normal flight the arrow should never be sideways, so we can use simplified physics. This allows us to bypass a GE physics glitch with objects travelling at very high speeds which, for an arrow, is important.)
If you are using slight manual control over the physics, just disable them and allow the GE to take over. If you went with my second method, the best thing I can come up with is to end the arrow and add in a separate version that has rigid body enabled- line up their orientations and apply the velocity to the new one, and the GE will take care of the rest.

Getting an arrow to stick in newer releases of blender is fairly easy- disable physics, and set the new parent to be the hit object.

This will not take armatures into account, so arrows will not stick into individual limbs of animated characters or whatnot, but until the BGE has better armature integration you may just have to do without this, or hack together armature collision by parenting hit boxes to individual bones of all animated objects (this will be pretty resource expensive)

Other things you could add could include the arrow going in different depths depending on the density of the material, and possibly continuing on through thinner and lighter materials, but I think I’ve written enough right now.

Thanks alot for the answers guys :smiley: Mkay, I’ve been modeling an island all day long so my brain is a bit scrambled XD Much of what you’ve said is exactly how I thought of it although I don’t know the python syntax. I’ll look it up don’t worry :stuck_out_tongue: I know where the search function is XD