Help with collision
-
Have no idea how to do this but I'm trying to make a space ship shooter I've got the movement down and kinda the shooting but I want the ship to collide with the player or vice versa and I want the ship to be destroyed im gonna keep trying but any help would be useful.
-
You've got lots of different ways to do it.
Are you making a 2D game or 3D? Are you using the sprite commands or just using drawImage(), etc?
Depending on how you're making this game, different methods of collision might be best.
The quickest, simplest, and also least accurate way would be to use distance.
dist = distance( shipPositionVector, playerPositionPlayer ) if dist < x then // here is where you want to do the collision result. So, health decreases or ship is destroyed etc. // Remember, if you have multiple ships to collide with this will need to be a For Loop which counts over ever ship. endif
There's an instance of this in the Sprite Game tutorial, but using the sprite commands:
72. if distance( playerPos, rocks[i].pos ) < rockSize.x / 2 - 50 and alive then 73. alive = false 74. setSpriteAnimation( expSpr, 0, 89, 14 ) 75. setSpriteLocation( expSpr, playerPos ) 76. setSpriteScale( expSpr, scale ) 77. setSpriteVisibility( expSpr, true ) 78. setSpriteVisibility( playerSpr, false ) 79. endif
From this tutorial page: https://fuzearena.com/help/view/Sprite Game
Let me know if you need anything else! I'm sure lots more people will have better ideas. The other, more accurate way of doing it is with a series of If statements.
-
It's a 3d game