Update docs

This commit is contained in:
Cory Petkovsek 2019-08-25 23:34:43 +09:00
parent 4ec82928b4
commit 3e40ceb844
21 changed files with 214 additions and 77 deletions

View File

@ -1,11 +1,22 @@
# Collision # Collision
Physics based collision is enabled by default. Physics based collision is enabled by default. It provides both raycasting and collision detection.
You can turn it on or off by setting the `generate_collision` option on any of the terrain nodes. Or you can enable or disable it in code. You can turn it on or off by setting the `generate_collisions` option on any of the terrain nodes. Or you can enable or disable it in code.
The collision is built along with the mesh. So any blocks that have already been built will not be affected by the setting unless they are regenerated. The collision is built along with the mesh. So any blocks that have already been built will not be affected by the setting unless they are regenerated.
## Debugging
You can also turn on the collision wire mesh for debugging. In the editor, look under the Debug menu for `Visible Collision Shapes`.
![heightmap](https://user-images.githubusercontent.com/632766/62386300-61ab9c00-b592-11e9-8f01-3f454593dd91.gif)
# Alternatives To Physics Based Collision
There are some alternative collision related tools available: There are some alternative collision related tools available:
## Axis Aligned Bounding Box (Blocky only) ## Axis Aligned Bounding Box (Blocky only)
@ -28,43 +39,28 @@ func _physics_process(delta):
velocity = motion / delta velocity = motion / delta
``` ```
## Raycasting (Blocky or Smooth) ## Raycasting
You can manually send out raycasts from your character to see how far away from the terrain it is. You can also do this with any of your objects. You may want to use raycasts when collision has not been enabled. For instance picking the terrain with the mouse cursor. `VoxelTerrain` supports a rudimentary raycast. `VoxelLODTerrain` does not.
_Note: Raycasting in VoxelLodTerrain requires the merging of [PR #29](https://github.com/Zylann/godot_voxel/pull/29), which is a work in progress. It works fine on LOD 0, but not the others._ Returned values are blocky, integer grid positions, while physics based raycasting will return fine-grained floating point positions.
Here's an example of how it can work. For a character 2 units tall, this runs a raycast directly down to prevent the character from sinking into the ground. `on_ground` is a boolean that tells the jump function whether it can fire or not. The usage is simple: `terrain.raycast(start_postion, direction, max_distance)`
```
# Apply gravity to downward velocity
velocity.y += delta*GRAVITY
# But clamp it if we hit the ground
if terrain.raycast(head_position, Vector3(0,-1,0), PLAYER_HEIGHT):
velocity.y = clamp(velocity.y, 0, 999999999)
on_ground = true
```
Then for lateral motion, you can test with something like this. We run a raycast at foot/knee level, then a little higher up (head level, since the granularity provided by the raycast is not very fine). Upon success, it returns a dictionary with the following values:
If it's clear at head level, but not at foot level then we're looking at a sloped terrain. We move the character up a little bit to help it traverse the terrain. It is a little rough, but serves as a working example.
```
func test_and_move(pos, dir) -> Vector3:
# If raycast hits at knee level (-1.5)
if terrain.raycast(Vector3(pos.x, pos.y-1.5, pos.z), dir, 1):
# Then test at head level and move character up a little if clear
if !terrain.raycast(pos, dir, 1) :
translate(Vector3(0,.15,0))
return dir
# Both hit, can't move
return Vector3(0,0,0)
# Otherwise, free to move
else:
return dir
``` ```
hit["position"] - Vector3 integer position where the ray hit
hit["prev_position"] - Previous Vector3 integer position the ray occupied before it hit
```
On failure, it will return an empty dictionary:`Variant()`. You can logically test this result:
```
if terrain.raycast(...):
do something
```
--- ---
* [Next Page](06_custom-streams.md) * [Next Page](06_custom-streams.md)

View File

@ -14,11 +14,14 @@ These classes are exposed to GDScript. This information is also available within
* [VoxelMesherDMC.md](VoxelMesherDMC.md) * [VoxelMesherDMC.md](VoxelMesherDMC.md)
* [VoxelMesherTransvoxel.md](VoxelMesherTransvoxel.md) * [VoxelMesherTransvoxel.md](VoxelMesherTransvoxel.md)
* [VoxelStream.md](VoxelStream.md) * [VoxelStream.md](VoxelStream.md)
* [VoxelStreamBlockFiles.md](VoxelStreamBlockFiles.md)
* [VoxelStreamFile.md](VoxelStreamFile.md)
* [VoxelStreamImage.md](VoxelStreamImage.md) * [VoxelStreamImage.md](VoxelStreamImage.md)
* [VoxelStreamNoise.md](VoxelStreamNoise.md) * [VoxelStreamNoise.md](VoxelStreamNoise.md)
* [VoxelStreamRegionFiles.md](VoxelStreamRegionFiles.md)
* [VoxelStreamTest.md](VoxelStreamTest.md) * [VoxelStreamTest.md](VoxelStreamTest.md)
* [VoxelTerrain.md](VoxelTerrain.md) * [VoxelTerrain.md](VoxelTerrain.md)
--- ---
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -96,4 +96,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -28,4 +28,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -106,4 +106,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -64,4 +64,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -38,4 +38,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -14,11 +14,18 @@ _Godot version: 3.2_
## Properties: ## Properties:
#### » bool generate_collision #### » int collision_lod_count
`set_generate_collision (value)` setter `set_collision_lod_count (value)` setter
`get_generate_collision ()` getter `get_collision_lod_count ()` getter
#### » bool generate_collisions
`set_generate_collisions (value)` setter
`get_generate_collisions ()` getter
#### » int lod_count #### » int lod_count
@ -86,4 +93,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -67,4 +67,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -28,4 +28,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -26,9 +26,6 @@ _Godot version: 3.2_
#### » bool get_occlusion_enabled ( ) const #### » bool get_occlusion_enabled ( ) const
#### » Dictionary get_profiling_info ( ) const
#### » void set_library ( VoxelLibrary voxel_library ) #### » void set_library ( VoxelLibrary voxel_library )
@ -46,4 +43,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -79,4 +79,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -25,4 +25,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -31,4 +31,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -0,0 +1,35 @@
# Class: VoxelStreamBlockFiles
Inherits: VoxelStreamFile
_Godot version: 3.2_
## Online Tutorials:
## Constants:
## Properties:
#### » String directory
`set_directory (value)` setter
`get_directory ()` getter
## Methods:
## Signals:
---
* [Class List](Class_List.md)
* [Doc Index](../01_get-started.md)
_Generated on Aug 25, 2019_

View File

@ -0,0 +1,45 @@
# Class: VoxelStreamFile
Inherits: VoxelStream
_Godot version: 3.2_
## Online Tutorials:
## Constants:
## Properties:
#### » VoxelStream fallback_stream
`set_fallback_stream (value)` setter
`get_fallback_stream ()` getter
#### » bool save_fallback_output
`set_save_fallback_output (value)` setter
`get_save_fallback_output ()` getter
## Methods:
#### » Vector3 get_block_size ( ) const
## Signals:
---
* [Class List](Class_List.md)
* [Doc Index](../01_get-started.md)
_Generated on Aug 25, 2019_

View File

@ -39,4 +39,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -46,4 +46,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -0,0 +1,72 @@
# Class: VoxelStreamRegionFiles
Inherits: VoxelStreamFile
_Godot version: 3.2_
## Online Tutorials:
## Constants:
## Properties:
#### » int block_size_po2
`set_block_size_po2 (value)` setter
`get_region_size_po2 ()` getter
#### » String directory
`set_directory (value)` setter
`get_directory ()` getter
#### » int lod_count
`set_lod_count (value)` setter
`get_lod_count ()` getter
#### » int region_size_po2
`set_region_size_po2 (value)` setter
`get_region_size_po2 ()` getter
#### » int sector_size
`set_sector_size (value)` setter
`get_sector_size ()` getter
## Methods:
#### » void convert_files ( Dictionary new_settings )
#### » int get_block_size_po2 ( ) const
#### » Vector3 get_region_size ( ) const
## Signals:
---
* [Class List](Class_List.md)
* [Doc Index](../01_get-started.md)
_Generated on Aug 25, 2019_

View File

@ -59,4 +59,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_

View File

@ -11,29 +11,14 @@ _Godot version: 3.2_
## Constants: ## Constants:
#### » BlockDirtyState.BLOCK_NONE = 0
#### » BlockDirtyState.BLOCK_LOAD = 1
#### » BlockDirtyState.BLOCK_UPDATE_NOT_SENT = 2
#### » BlockDirtyState.BLOCK_UPDATE_SENT = 3
#### » BlockDirtyState.BLOCK_IDLE = 4
## Properties: ## Properties:
#### » bool generate_collision #### » bool generate_collisions
`set_generate_collision (value)` setter `set_generate_collisions (value)` setter
`get_generate_collision ()` getter `get_generate_collisions ()` getter
#### » bool smooth_meshing_enabled #### » bool smooth_meshing_enabled
@ -77,9 +62,6 @@ _Godot version: 3.2_
#### » Vector3 block_to_voxel ( Vector3 block_pos ) #### » Vector3 block_to_voxel ( Vector3 block_pos )
#### » int get_block_state ( Vector3 block_pos ) const
#### » Material get_material ( int id ) const #### » Material get_material ( int id ) const
@ -112,4 +94,4 @@ _Godot version: 3.2_
* [Class List](Class_List.md) * [Class List](Class_List.md)
* [Doc Index](../01_get-started.md) * [Doc Index](../01_get-started.md)
_Generated on Aug 02, 2019_ _Generated on Aug 25, 2019_