Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore Godot 3D and implement voxels collisions in physics testbed #1

Open
acs opened this issue Aug 24, 2020 · 8 comments
Open

Explore Godot 3D and implement voxels collisions in physics testbed #1

acs opened this issue Aug 24, 2020 · 8 comments
Labels

Comments

@acs
Copy link
Contributor

acs commented Aug 24, 2020

Godot 3D tutorial: https://docs.godotengine.org/en/stable/tutorials/3d/introduction_to_3d.html#spatial-node

Starting to learn with it!

This tutorial does not cover the basics pretty well. Let's find others:

https://www.reddit.com/r/godot/comments/an0iq5/godot_tutorials_list_of_video_and_written/

Godot and MagicaVoxel: https://www.reddit.com/r/godot/comments/9497gz/how_to_3d_voxels_to_pixel_art_with_viewports/

The 3D tutorials are not as complete as the 2D ones (https://godotforums.org/discussion/15767/request-beginner-3d-step-by-step-tutorial) and most of them are inside videos.

For example:

https://www.youtube.com/watch?v=VeCrE-ge8xM

Let's take a look to this eBook: https://godottutorials.pro/free-ebook-godot-game-development/ link

This tutorial seems to be a good reference: https://godottutorials.pro/fps-godot-tutorial/ (the same than the one included in the book).

And this article bout Godot tutorials for Beginners is also pretty interesting, pointing to 3D resources: https://conceptartempire.com/godot-tutorials/

I would focus in this youtube tutorial:

https://www.youtube.com/watch?v=VeCrE-ge8xM Godot 3.1: Creating a Simple 3D Game: Part 1 (Intro, Nodes & 3D Physics) #GodotEngine

All of those were started in Voxelers/mcthings#137

@acs
Copy link
Contributor Author

acs commented Aug 24, 2020

Also, a good learning resource are the Godot demos about 3D. Once we have learnt the basic concepts around 3D learning by examples could be the best option.

The final of the trip is implementing Voxelers/mcthings#137

@acs acs changed the title Explore Godot 3D Explore Godot 3D and Implement voxels collisions in Godot physics testbed Aug 24, 2020
@acs acs changed the title Explore Godot 3D and Implement voxels collisions in Godot physics testbed Explore Godot 3D and implement voxels collisions in physics testbed Aug 24, 2020
@acs
Copy link
Contributor Author

acs commented Aug 24, 2020

Ok, let's focus on: https://godottutorials.pro/fps-godot-tutorial/ I will try to follow it as I did for the 2D game tutorial.

I have tested the finished project at it is promising. More motivation to complete the tutorial:

Screenshot from 2020-08-24 23-00-20

@acs
Copy link
Contributor Author

acs commented Aug 25, 2020

One of the most important things in 3D is to feel comfortable moving in the 3D world. Godot tries to mimic Blender but I can not reproduce the experience. I can zoom in and zoom out with "scrolling mouse". And I can rotate using the 3D axis GUI at top right like in Blender, or using right click and the mouse moves at the same time.

According to the Settings:

Screenshot from 2020-08-25 11-54-28

It should be like Blender. Maybe the issue is that I am using a touch pad.

Looking to the video: https://www.youtube.com/watch?v=0Kr5-NXzmfs

SHIFT-F enters you in Freelook which is the best mode to move around your 3D world.

With Right Click pressed y AWSD you can move similar to freelook. And also you can move the mouse to rotate.

Ok, enough to continue now learning with the tutorial.

@acs
Copy link
Contributor Author

acs commented Aug 26, 2020

Ok, the tutorial reached a point when it says: "Go ahead and create an environment." At this momento we must do a lof of things alone. Resize/scale the ground so it holds all the objects. Start adding all the objects, rotating them as needed to recreate the environment. I will try to do it but probably, the tutorial must give some steps on howto create the "environment".

For example, for scaling the ground so we can place over it the full scene:

Screenshot from 2020-08-26 10-09-39

With it a 10x1x10 (x, y, z, 100 squares) ground is created.

@acs
Copy link
Contributor Author

acs commented Aug 26, 2020

I have found that it is critical to understand how to position the camera in order to see the scene. You must understand how to do it in order to be comfortable. Use the Preview button to see how everything looks from the camera vision.

Screenshot from 2020-08-26 10-24-50

And of course playing with lights is critical. In this case example I am turning of/off a directorial light.

Screenshot from 2020-08-26 10-30-54

lights3d

@acs
Copy link
Contributor Author

acs commented Aug 27, 2020

The tutorial is going pretty well. After creating the environment from the models, partially, I have created the player, with her camera, so it is a first person shooter: the camera are the eyes of the player!

And right now, I am learning howto implement the movement of the player. It is pretty similar to what we did in 2D but in 3D, so it is a bit more complex. In the process I have seen that in GDScript you can use types!

var moveSpeed : float = 5.0

The basic idea is the same:

  • When an input is event is detected (keyboard or mouse), capture it:
func _input (event): 
	# did the mouse move?
	if event is InputEventMouseMotion:
		mouseDelta = event.relative
  • When drawing every frame (if we have 60 fps, 60 calls per second), godot calls the _process method. In this method we implement the rotation
func _process (delta):
 
	# rotate camera along X axis
	camera.rotation_degrees -= Vector3(rad2deg(mouseDelta.y), 0, 0) * lookSensitivity * delta
 
	# clamp the vertical camera rotation
	camera.rotation_degrees.x = clamp(camera.rotation_degrees.x, minLookAngle, maxLookAngle)
 
	# rotate player along Y axis
	rotation_degrees -= Vector3(0, rad2deg(mouseDelta.x), 0) * lookSensitivity * delta
 
	# reset the mouse delta vector
	mouseDelta = Vector2()

In delta we have the delta time between frames. It is used to measure the time the mouse has been pressed in order to adjust
the amount of rotation to be done. With "lookSensitive" we can adjust the rotation speed. mouseDelta comes from the _input method. Not yet sure why to rotate camera in X we use the mouseDelta.y.

It is curious that for "godot y" rotation we use the camera, and for x, we use the player scene complete. Not sure why yet.

  • For the player movement, we have predefined some actions when hitting WASD keys: move_forward ... and for implementing it, we use the method called for physics processing. Why not doing here also the rotation? Not sure.
# called every physics step
func _physics_process (delta):
		# reset the x and z velocity
	vel.x = 0
	vel.z = 0
	 
	var input = Vector2()
	 
	# movement inputs
	if Input.is_action_pressed("move_forward"):
		input.y -= 1
	if Input.is_action_pressed("move_backward"):
		input.y += 1
	if Input.is_action_pressed("move_left"):
		input.x -= 1
	if Input.is_action_pressed("move_right"):
		input.x += 1
	 
	# normalize the input so we can't move faster diagonally
	input = input.normalized()
	
	# get our forward and right directions
	var forward = global_transform.basis.z
	var right = global_transform.basis.x
	# set the velocity
	vel.z = (forward * input.y + right * input.x).z * moveSpeed
	vel.x = (forward * input.y + right * input.x).x * moveSpeed
	 
	# apply gravity
	vel.y -= gravity * delta
	 
	# move the player
	vel = move_and_slide(vel, Vector3.UP)

	# jump if we press the jump button and are standing on the floor
	if Input.is_action_pressed("jump") and is_on_floor():
		vel.y = jumpForce

This is the more complex code. Here we control the velocity of the player in 3D. x and z and computed using the constant moveSpeed (5) and the keys pressed. y is computed using the gravity force (12) and the time passed under this force.

And finally, if we press jump key (space) and we are on the floor, they y velocity is adjusted to jump!

And with the above code, all the logic for 3D moving and rotating the player is implemented. Cool!

It is pretty similar to what we did for 2D but we need to include the third dimension.

@acs
Copy link
Contributor Author

acs commented Aug 27, 2020

Ok, shooting also implemented. It is pretty easy to understand it.

shooting

It is mostly physics all.

@acs
Copy link
Contributor Author

acs commented Sep 9, 2020

Don't forget to implement Voxelers/mcthings#122 in Godot!

The goal is to add two models created in MagicaVoxel and collide them inside a Godot scene!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant