https://odysee.com/@Lethn:3/Sandbox-Shooter-Gameplay-1:9
I'm steamrolling through code right now which is fantastic and will be posting some by the gods stuff eventually. Once you get over the initial teething problems of learning a new engine Godot is pretty straightforward considering how tedious I found ragdoll physics and vehicles in Unity. These are the two tutorials that I've used for reference.
extends KinematicBody
var mouseSensitivity = 0.2
var direction = Vector3()
var gravityVector = Vector3()
var horizontalVelocity = Vector3()
var movement = Vector3()
var speed = 30
var gravity = 40
var jumpHeight = 25
var horizontalAcceleration = 6
onready var mouseLookNode = $MouseLookNode
onready var playerCamera = $MouseLookNode/PlayerCamera
var canEnterDriverSeat = false
var vehicleDriverArea
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
playerCamera.make_current()
func _input(event):
if event is InputEventMouseMotion:
rotate_y(deg2rad(-1 * event.relative.x * mouseSensitivity))
mouseLookNode.rotate_x(deg2rad(event.relative.y) * mouseSensitivity)
mouseLookNode.rotation.x = clamp (mouseLookNode.rotation.x, deg2rad(-89), deg2rad(89))
func _physics_process(delta):
direction = Vector3()
if not is_on_floor():
gravityVector += Vector3.DOWN * gravity * delta
else:
gravityVector = -get_floor_normal() * gravity
if Input.is_action_just_pressed("Space") and is_on_floor():
gravityVector = Vector3.UP * jumpHeight
if Input.is_action_pressed("W"):
direction += transform.basis.z
elif Input.is_action_pressed("S"):
direction -= transform.basis.z
if Input.is_action_pressed("A"):
direction += transform.basis.x
elif Input.is_action_pressed("D"):
direction -= transform.basis.x
if Input.is_action_just_pressed("E") and canEnterDriverSeat == true:
vehicleDriverArea.ActivateVehicleCamera()
queue_free()
direction = direction.normalized()
horizontalVelocity = horizontalVelocity.linear_interpolate(direction * speed, horizontalAcceleration * delta)
movement.z = horizontalVelocity.z + gravityVector.z
movement.x = horizontalVelocity.x + gravityVector.x
movement.y = gravityVector.y
move_and_slide(movement, Vector3.UP)
extends VehicleBody
var isScriptEnabled = false
var isPlayerInVehicle = false
onready var vehicleDriverArea = $VehicleDriverArea
onready var vehicleCameraRotate = $VehicleCameraRotate
onready var vehicleCamera = $VehicleCameraRotate/VehicleCamera
onready var exitPointDriverSeat = $ExitPointDriverSeat
var exitVehicleCooldownTimer = 1.0
export (PackedScene) var player
func _ready():
vehicleDriverArea.vehicleBody = self
isPlayerInVehicle = false
func _physics_process(delta):
if isPlayerInVehicle == true:
exitVehicleCooldownTimer -= delta
if exitVehicleCooldownTimer <= 0.0:
exitVehicleCooldownTimer = 0.0
if isScriptEnabled == true:
steering = lerp(steering, Input.get_axis("D", "A") * 0.4, 5 * delta)
engine_force = Input.get_axis("S", "W") * 200
if Input.is_action_just_pressed("E") and isPlayerInVehicle == true and exitVehicleCooldownTimer <= 0.0:
DeactivateVehicleCamera()
exitVehicleCooldownTimer = 1.0
func ActivateVehicleCamera():
isScriptEnabled = true
isPlayerInVehicle = true
vehicleCameraRotate.isScriptEnabled = true
vehicleCamera.make_current()
set_process(true)
func DeactivateVehicleCamera():
isScriptEnabled = false
isPlayerInVehicle = false
vehicleCameraRotate.isScriptEnabled = false
var localPlayer = player.instance()
get_tree().get_root().add_child(localPlayer)
localPlayer.global_transform.origin = exitPointDriverSeat.global_transform.origin
set_process(false)
extends Area
var vehicleBody
func _on_VehicleDriverArea_body_entered(body):
if body.is_in_group("Player"):
body.canEnterDriverSeat = true
body.vehicleDriverArea = self
vehicleBody.set_process(true)
func _on_VehicleDriverArea_body_exited(body):
if body.is_in_group("Player"):
body.canEnterDriverSeat = false
body.vehicleDriverArea = null
vehicleBody.set_process(false)
func ActivateVehicleCamera():
vehicleBody.ActivateVehicleCamera()