james7132 / DanmakU

An open source Danmaku development kit for Unity3D.
https://danmaku.jamessliu.com/
MIT License
238 stars 50 forks source link

Uninitialized positions passed to collisions functions #35

Closed TotallyGatsby closed 6 years ago

TotallyGatsby commented 6 years ago

Causing collisions to occur, even when the collider is nowhere near the bullet.

Attached is a mp4 showing the issue (Happy to upload to youtube or something if you'd prefer.) Note the bullets turning red when the collider (attached to the ship sprite) isn't close to them.

An example of a Danmaku's OldPosition and Position the moment it triggers a collision: OldPosition (271384100000000000000.0, 236805600000000000000.0) Position (300.0, 0.0)

Which is pretty clearly uninitialized data leaking into physics calculations.

I was able to fix this behavior by initializing OldPosition on a Danmaku whenever a Danmaku was created.

I added: OldPositions[danmaku.Id] = danmaku.position;

in three places in DanmakuPool.cs. (I'm putting together a pull request.)

video.zip