...
This commit is contained in:
parent
1e22d28754
commit
6b926d3afe
126 changed files with 128562 additions and 104297 deletions
|
|
@ -0,0 +1,16 @@
|
|||
Sprite2D node
|
||||
|
||||
F => focus view on object
|
||||
|
||||
To get type information in code auto-completion, go to _Editor -> Editor Settings_, and in the _Text Editor -> Completion_ section, turn on the checkbox named _Add Type Hints_. You can also search for "type hints" in the search bar at the top of the window to find it quickly.
|
||||
|
||||
|
||||
`Vector2` values have a function named `angle()` that calculates and returns the vector's angle in radians. If we assign that to the ship's rotation, it will turn to face its move direction.
|
||||
|
||||
```gdscript
|
||||
var velocity = Vector2(480, -480)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
position += velocity * delta
|
||||
rotation = velocity.angle()
|
||||
````
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
https://school.gdquest.com/courses/learn_2d_gamedev_godot_4/to_space_and_beyond/taking_control
|
||||
|
||||
```gdscript
|
||||
extends Sprite2D
|
||||
var direction := Vector2(0,0)
|
||||
var max_speed := 600.0
|
||||
var velocity = Vector2(0, 0)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
direction.x = Input.get_axis("move_left", "move_right")
|
||||
direction.y = Input.get_axis("move_up", "move_down")
|
||||
|
||||
if direction.length() > 1.0:
|
||||
direction = direction.normalized()
|
||||
|
||||
velocity = direction * max_speed
|
||||
position += velocity * delta
|
||||
if direction.length() > 0.0:
|
||||
rotation = velocity.angle()
|
||||
```
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
```python
|
||||
func _process(delta: float) -> void:
|
||||
var direction := Vector2(0, 0)
|
||||
direction.x = Input.get_axis("move_left", "move_right")
|
||||
direction.y = Input.get_axis("move_up", "move_down")
|
||||
|
||||
if direction.length() > 1.0:
|
||||
direction = direction.normalized()
|
||||
|
||||
if Input.is_action_just_pressed("boost"):
|
||||
max_speed = boost_speed
|
||||
get_node("Timer").start()
|
||||
|
||||
velocity = direction * max_speed
|
||||
position += velocity * delta
|
||||
|
||||
if direction.length() > 0.0:
|
||||
rotation = velocity.angle()
|
||||
```
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
```python
|
||||
extends Sprite2D
|
||||
var direction := Vector2(0,0)
|
||||
var max_speed := 300.0
|
||||
var velocity = Vector2(0, 0)
|
||||
var boost_speed := 1500.0
|
||||
var normal_speed := 300.0
|
||||
var desired_velocity := Vector2()
|
||||
var steering_factor := 10
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
var direction := Vector2(0, 0)
|
||||
direction.x = Input.get_axis("move_left", "move_right")
|
||||
direction.y = Input.get_axis("move_up", "move_down")
|
||||
|
||||
if direction.length() > 1.0:
|
||||
direction = direction.normalized()
|
||||
|
||||
if Input.is_action_just_pressed("boost"):
|
||||
max_speed = boost_speed
|
||||
get_node("Timer").start()
|
||||
|
||||
desired_velocity = max_speed * direction
|
||||
var steering = desired_velocity - velocity
|
||||
|
||||
velocity += steering * steering_factor * delta
|
||||
position += velocity * delta
|
||||
|
||||
if direction.length() > 0.0:
|
||||
rotation = velocity.angle()
|
||||
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
max_speed = normal_speed
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue