Hey all, been grating my head against the symptoms of this problem for days. I'm trying to do my own simple 2d physics so that I can tweak behaviors further than just rigid collisions.
I have an entity class that keeps track of velocity, mass, and changes position of entities in update. I have 3 classes that inherit from entity: Player, Enemy, and Bullet.
There's also a collide class applied to all the prefabs that will replace 2 colliding object's velocities with their new velocities after a collision.
The bullet works perfectly. The bullet will bounce off an enemy, and the enemy has the appropriate velocity added to it after the bounce.
Enemies and the player completely ignore each other. The collide script replaces the entity's velocity completely at the moment, but it feels like the player/enemy script is replacing the new velocity with the old one before movement is calculated. I haven't the foggiest idea how an object can detect if one of it's variables has been changed by another object to find out if it's being overridden. There's no implicit assigning of velocity in any script except for collide, everything else is += an impulse from player controls. I've even commented everything out of the enemy code just to make sure nothing within it was overriding the velocity.
I have debug lines showing appropriate new velocities sampled from the player and enemies at the moment of collision (well constantly since they penetrate eachother).
I've been looking at why the player and enemy are broken, but I guess I should be looking at why the bullet actually works. The bullet is doing almost nothing (rotates self visually, sets initial velocity and starts a coroutine to kill itself), and the enemy file is literally empty, so I'm not sure what the difference is.
All 3 prefabs are using sphere colliders as triggers to detect the collision event, and have rigid bodies so that the triggers actually work. Initially the bullets didnt have the collide script attached, but I added it and nothing changed.
I dont know what to do or where to look, and cant make any progress until I figure this out. Any help would be most appreciated. Even suggestions on how to further troubleshoot this.
Oh, forgot to mention. The player and 2 enemies in the scene were dropped in as prefabs, the bullets of course are created by the player. I didn't want to get into spawning before movement worked. Could this be causing issues?
– anon32706914I dropped a bullet into the scene and it bounced off the enemy when I hit play.
– anon32706914You might not be able to, but sharing a working project would allow for proper solving, as from your description it's unlikely that a solution will popup without a proper look at your system.
– Jean-Fabre