entitycollided doesnt return an int; returns an entity handle?

Started by William, May 14, 2023, 09:33:52

Previous topic - Next topic

William

different from blitz3d, im trying to convert some code here.

this is a bit of code im trying to convert into openb3d/blitzmax

Local CollidedCollidable:Int = EntityCollided(PlayerCollider,GroupEnvironment)
 If( CollidedCollidable = 0 )
  PlayerIsOnGround = False
 ElseIf( CollidedCollidable <> 0 )
  PlayerIsOnGround = True
 EndIf

but instead of a int or boolean value it returns an entity instead of an int as in b3d. is there a workaround for this?
im still interested in oldschool app/gamedev

William

scaremonger messaged a workaround on discord:
Local CollidedCollidable:TEntity = EntityCollided(PlayerCollider,GroupEnvironment)
 If( Not CollidedCollidable )
  PlayerIsOnGround = False
 Else
  PlayerIsOnGround = True
 EndIf

i will work on this section of code and test it. later.
EDIT: GWRON fixed it, it remains to be fully tested however.
im still interested in oldschool app/gamedev

Midimaster

No! The EntityCollided() return the Entity which collided! In human words: It tells you who you bumped into!

So it is a base for a IF-branch:

If EntityCollided(PlayerCollider, GroupEnvironment) = GroundMesh
     PlayerIsOnGround = True
EndIf

Of course you can go the way via a local variable. but this is only necessary, if you want to check more than one possible collision.

Example:
Local WhoCollided:TEntity = EntityCollided(PlayerCollider,GroupEnvironment)

If WhoCollided=GroundMesh
     print "Player is on ground "
ElseIf WhoCollided=Player2
     print "both Players both collided"
ElseIf WhoCollided=Enemy
     print "Crash with enemy"
Else
    print "no collision happened"
EndIf
...back from Egypt