arrow physics.

Hi everyone.

You’ve probably seen my gameproject. It is a 2d game where you play as an archer.

The case now is:
When the arrow is released it will always stay at the same velocity, and doesn’t care about gravity:

What I would like is this:

Can anybody help me with achieving this?
Notice that it is for a 2d game, not 3d.

Thanks in advance

Doesn’t basic rigidbody physics with translation lock in your desired axis work?

You can use a rigid body, with alignAxisToVect(own.worldLinearVelocity,0,.1)

as for impact etc, I would cast a ray out own.worldLinearVelocity*.2

Thanks, I’ll try tomorrow.

You could add a new arrow from an invisible layer and give him some linear veloncity with the addobjectactuator. And you can use the track to actuator with an empty as target to make sure that the arrowhead will show in the current flight direction. Then you should get a nice flight path
Here is a link (it’s a german forum) with an example in the second to last post. It’s in 3d but you can use it for 2d too.
Maybe the performace in the example is a little bad that’s because shadows are enabled :wink:

I use the method I described for all the projectiles in Non_juggernaut.

Here’s a little something I slapped together. Basically an implementation of BPR’s idea, although I use a radar sensor instead (ray was just not doing the job)

Move the mouse up and down to aim, hold left button to build up force, and let go to fire the arrow!
(logic brick errors make arrows drop at your feet, but oh well)

It sort of works! The arrows don’t stick every time, and sometimes clip through geometry, etc etc.

archery.blend (494 KB)

There is no limit to the amount of force that you can build up, but there probably should be. High-speed projectiles tend to have increasingly crummy hit detection :wink:

that is why I use the ray :smiley:
the faster the arrow moves, the longer the ray.

also fixed double execution, and fire on init :stuck_out_tongue:


archeryBpr.blend (496 KB)

Ah, but I am being lazy and using sensor bricks!

Actually, the hit detection is totally broken, now that I play with it some more. The only reason the arrows stick at all is because they’re getting caught in the geometry. lines 11-12:

    own.worldLinearVelocity = 0
    own.worldAngularVelocity = 0

should be:

    own.worldLinearVelocity *= 0
    own.worldAngularVelocity *= 0

yeah, I just noticied the part



I did dat wrong

Now, its perfect!

Enjoy @hilkojj !


archeryBprFixed.blend (447 KB)

Yes, very nice! I was having trouble making the arrows stick. Good job!


here is the same file, but added impact forces :smiley:


archeryBprFixed (Impact).blend (502 KB)

Thanks for all your help, I’ll look at it tomorrow since I’m now on my mobile phone.

here you are sir!

Noticed applyMovement does not allways work

from bge import logic
import bge

cont = logic.getCurrentController()
own = cont.owner
ray = own.rayCast(own.worldPosition+(own.worldLinearVelocity*.025),own.worldPosition,0,'',0,0,0)

if ray[0] and 'done' not in own:
    own.worldLinearVelocity *= 0
    own.worldAngularVelocity *= 0
    own['done'] = True
elif 'done' not in own:
    own.worldLinearVelocity.y *= 0
    own.worldAngularVelocity.z *= 0
    if own.worldLinearVelocity.magnitude>.05:

used this instead and it fixed it,

Thanks BPR, it’s perfect. I’ll use this for my game and you’ll receive credit for your work ;).
Edit: sorry, Nines made also a part of it, thanks nines!

Help, in your blend the arrow moves along the X axis. In my game the arrows should move along the Y axis.
None of these work good:




Try changing the line

own.worldLinearVelocity.y *= 0


own.worldLinearVelocity.x *= 0

The line you’re trying to change is what’s aligning the arrow to its forward movement and giving it that ‘arcing fire’ look. This line here is what’s clamping it to the 2D plane and keeping it from going into the foreground/background.

Sorry, I can’t find that line… could you change the blend, so it all will go along the y axis instead of the x axis? Because I can’t solve it… :frowning:

I’ll take a crack at it in moment when get a chance, y+ arrow, y+bow?