Problem with EntityCollided
Blitz3D Forums/Blitz3D Beginners Area/Problem with EntityCollided
| ||
Hi trying to make an effective gravity. This code moves entity to 'ground' level at an increase rate, then it slowly sinks through ground. Tried a couple of different ways just cant get it right, would appreciate some help:) If EntityCollided(level, playerbox) = False; tests to see if collided with ground, if not increase gravity gravity# = gravity# + 0.1 EndIf ;Else ;If EntityCollided(playerbox, level) = true and gravity# > 0.0 If EntityCollided(level, playerbox) = True gravity# = 0.0 EndIf |
| ||
You can make Blitz automaticaly stop objects from moving when they collide. Read the help on 'Collisions'. Its tricky to find the entry as its not listed as a command, use a link from one of the other collision commands. Oh, any maybe check out the castle sample code which comes with Blitz, I am sure that must use collisions. Rhy :) |
| ||
I use collisions to stop them moving, but I am trying to implement a suitable gravity effect. For instance when character is falling then the further the fall, the faster the fall is. |
| ||
entitycollided needs the TYPE of the entity as the 2nd parameter. This is the Value you assigned with EntityType. Example given EntityType Level,2 entityType player,1 Collisions 1,2,2,2 while game ... updateworld() coco= entitycollided(player,2) if coco<>0 then print "player collided with "+ coco endif ... wend |
| ||
Multiply your gravity by a value just greater that 1, each run through the game loop. e.g. gravity# = gravity# * 1.001 - you'll need to experiment with the value to get it to 'look right'. This will make objects fall faster the longer they're falling. You may want to have a 'maximum velocity' to prevent falling objects from going too fast. |
| ||
Try using the Sin function. Increase an angle variable by say 1 every frame, plug that into Sin, and you'll get a gradually accelerating gravity :o) |
| ||
cheers jfk, just realised in help it says type, yeh it works better now. trying to get second part working now, but progress at least:) |
| ||
It's best to not solely rely on the collisions for gravity. A line pick from beneath the entity is best..you set the position the linepick starts from (from the entity pivot) and set its max distance; if it hits the ground then set gravity to -0.01 or something not too strong...if it does not detect the ground then set the gravity higher as you are in the air. Make sure your level is 'pickable' by setting the entitypickmode. If you rely on collisions alone you will have problems with walls and stuff in your level. |
| ||
Thanks all for the help, this is what I'm using at the moment, seems to be fine.; tests to see if collided with ground, if not increase gravity, resets to zero if touching If EntityCollided(playerbox, type_scenery) = False playergravity# = (playergravity# + gravityinc#) * 1.3 if playergravity# > 23.0 then playergravity# = 23.0 Else playergravity# = 0.0 EndIf ;apply gravity to the playerbox, and then move the camera to the place of the playerbox PositionEntity playerbox, EntityX(playerbox), EntityY(playerbox) - playergravity#, EntityZ(playerbox) |
| ||
What happens when you jump and hit a wall in you scenery? Zero gravity. Linepick will solve this. |
| ||
yes, I use a linepick too. A linepick that goes down to the shoes. this may be slightly more than the entityradius of the player. |