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.
https://www.blendpolis.de/viewtopic.php?f=15&t=48322&p=503958&hilit=pfeil+bogen#p503958
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:

Attachments

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.

arrowbrains.py lines 11-12:


    own.worldLinearVelocity = 0
    own.worldAngularVelocity = 0

should be:


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

yeah, I just noticied the part

own.applyMovement((own.getDistanceTo(ray[1],0,0),1)

lol!

I did dat wrong

Now, its perfect!

Enjoy @hilkojj !

Attachments

archeryBprFixed.blend (447 KB)

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

Thanks!

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

Attachments

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)
bge.render.drawLine(own.worldPosition+(own.worldLinearVelocity*.05),own.worldPosition,(1,0,0))




if ray[0] and 'done' not in own:
    print("STUCK")
    own.replaceMesh('stuckArrow',1,1)
    own.disableRigidBody()
    own.suspendDynamics()
    own.worldLinearVelocity *= 0
    own.worldAngularVelocity *= 0
    
    own.worldPosition=own.worldPosition+(own.worldOrientation.col[0]*own.getDistanceTo(ray[1]))
    own.setParent(ray[0])
    ray[0].applyImpulse(ray[1],own.worldOrientation.col[0]*(own['Force']*.125))
    own['done'] = True
    
elif 'done' not in own:
    own.worldLinearVelocity.y *= 0
    own.worldAngularVelocity.z *= 0
    if own.worldLinearVelocity.magnitude>.05:
        own.alignAxisToVect(own.worldLinearVelocity,0,0.1)

used this instead and it fixed it,
own.worldPosition=own.worldPosition+(own.worldOrientation.col[0]*own.getDistanceTo(ray[1]))

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:

own.alignAxisToVect(own.worldLinearVelocity,0,0.1)

own.alignAxisToVect(own.worldLinearVelocity,1,0.1)

own.alignAxisToVect(own.worldLinearVelocity,2,0.1)

Try changing the line


own.worldLinearVelocity.y *= 0

to


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?