Collision Problem
Blitz3D Forums/Blitz3D Beginners Area/Collision Problem
| ||
I'm trying to have my own reactions for collisions, But I for the life of me cant get CollisionEntity() or EntityCollided() to work. This was my latest relevant code for collisions. For e.enemy = Each enemy For x = 1 To CountCollisions(e\collisionF) If CollisionEntity(e\collisionF,x) = player\collisionF Then EntityColor(player\collisionF,100,0,0) Next Next ResetEntity(player\collisionF) Nothing seems to happen with this code. If I remove ResetEntity() then the player\collisionF will stop when it hits enemy\collisionF so I'm sure the problem is within this code. I'v been searching the forums and internet and I cant seem to find a solution. Although I have to say I found this format for collisions and I seem to like it, although it doesnt work for me lol. |
| ||
You are checking for collisions caused by 'e' colliding with the player - not the collisions caused by the player colliding with 'e'. If 'e' is not moving then it will generate no collisions of its own. If you want to check the collisions that the player has with 'e' then you need to go the other way around.... For x = 1 to countcollisions(player\collisionF) .. etc etc and check the collisionentity(player\collisionF,x) instead..... |
| ||
Wow Matty I feel like an idiot lol. I should have known that. Thanks allot man. I really appreciate it. |
| ||
I seem to have issues with resetentity(). If I keep it then the collision detection is really bad. This makes since, but is there another way to do my collisions this way without having my objects needing to slide or stop? |
| ||
ResetEntity() can indeed be used with collisions to know when a collision happens but without triggering a response. Try this : For e.enemy = Each enemy ;Counts the numbers of collisions on this collider CCount% = CountCollisions(e\Collider) ;If more than one collision happened If(CCount% > 0) ;Retrieves the other collider of the first collision OEntity% = CollisionEntity(e\Collider,1) ;If the other collider is the collider of Player If(OEntity% = p\Collider) ;Updates this npc (or updates player, do what you want) EntityColor(e\Collider,100,000,000) ;Resets the collision state of this collider ResetEntity(e\Collider) Endif Endif Next I normally use the same type/array for all npcs and the player. If the collider is the parent of the npc, then all others meshes and pivots of the npc will be moved depending on its position. If the collider is a child of the npc, then you will have to rotate and position it at the correct place each time a collision happens, else it will provoke strange behaviors. Last edited 2012 |
| ||
Thanks RemiD. What I actually did before I read this was I gave collisionF a default position so when it would move, it would return to where it should be witch worked. Although I decided to day I would be better off using entitydistance() for what I'm doing instead of collisions. I see what you did though and how it would work much better for when I need to use this sort of system in the future. Thanks a lot. |