#Make (sticky) projectile die on collision with terrain using scripts

1 messages · Page 1 of 1 (latest)

vale anchor
#

Potentially Relevant Projectile Information:

-- project45stdbullet.projectile

{
    -- ...
    "scripts" : ["project45stdbullet.lua"]
    "physics": "stickybullet"
    "movementSettings":{
        "collisionEnabled": true
    },
    "bounces" : 0,
    "collisionPoly": [
        [-8.5, 0],
        [0, 1.5],
        [8.5, 0],
        [0, -1.5]
    ],
    -- ...
}

project45stdbullet.lua:

function update(dt)
    if projectile.collision() then projectile.die() end
end
#

Do I have to manually query for tile collision?

#

yeap

#

Answer:

require "/scripts/vec2.lua"

function update(dt)
    if shouldDie() then projectile.die() end
end

function shouldDie()
    return world.lineTileCollision(mcontroller.position(), vec2.add(mcontroller.position(), vec2.norm(mcontroller.velocity())))
end
fallow tulip
#

Erm... if you want it to die on collision with terrain, why is it sticky?

umbral falcon
#

Straight flying

#

Prevents the bouncing

fallow tulip
#

"bounces": 0 prevents bouncing and "physics": "laser" flies straight

#

so does "physics": "bullet" for that matter

umbral falcon
#

incorrect

#

projectiles bounce no matter what even with 0 bounces

#

its hardcoded

#

with 0 bounces, they die at the end of the step that made it bounce

#

so in this sequence
start tick
bounce
die
end tick

#

so when it collides and its not sticky, it bounces

#

by being sticky it stays straight

#

@fallow tulip

fallow tulip
#

And the detectable difference is...?

worn oxide
umbral falcon
#

a few things, trails mostly

#

rotations too