Everything I've ever made so far has been same state, that is, walking everywhere. This time around, I'm looking to use at-will vehicles. Jump on a horse or grab a canoe and go. Whenever and wherever you find a horse or canoe. I'm really not sure how to implement this.
I have everything set up as enums for the different transportation states, I have a visual map of how things should go (can only dive from a swim state, can't sneak while on a horse, etc.), and I use signals for each state.
extends KinematicBody
### CHECK THE MODE OF TRANSPORTATION ###
enum {
WALK,
SNEAK,
HORSE,
CANOE,
SWIM,
DIVE
}
var move_state = WALK
## DEFAULT MOVEMENT SPEEDS ETC. ###
export var speed = 5
export var speed_rotation : float = 50
export var fall_acceleration = 75
var velocity = Vector3.ZERO
signal walking
signal sneaking
signal riding
signal paddling
signal swimming
signal diving
### GET THE ANIMATIONS ###
onready var animationPlayer = $kiyuga/AnimationPlayer
### MAKE IT ALL WORK SOMEHOW ###
func _process(delta):
match move_state:
WALK:
walk_state(delta)
SNEAK:
sneak_state(delta)
HORSE:
horse_state(delta)
CANOE:
canoe_state(delta)
SWIM:
swim_state(delta)
DIVE:
dive_state(delta)
### ALL LAND TRANSPORTATION STATES HAVE THE ABILITY TO USE RANGED WEAPONS, BEAD ABILITIES, AND CONSUMABLES ###
### CAMERA CONTROL IS ALSO AVAILABLE TO ALL STATES ###
### REGULAR WALK STATE, FOR EXPLORING AND SUCH ###
### CONTROLS INCLUDE HEAVY ATTACK, ATTACK, BEAD, CONSUMABLE, INTERACT, AND DODGE ###
### THESE ARE ALL THE STANDARD, DEFAULT ANIMATIONS ###
### DETECTIONS ARE NORMAL ###
func walk_state(delta):
var direction = Vector3.ZERO
if Input.is_action_pressed("move_right"):
rotation_degrees.y -= speed_rotation * delta
if Input.is_action_pressed("move_left"):
rotation_degrees.y += speed_rotation * delta
if Input.is_action_pressed("move_forward"):
direction += transform.basis.z
if Input.is_action_pressed("move_backward"):
direction -= transform.basis.z
animationPlayer.play_backwards("Walk1")
if direction != Vector3.ZERO:
direction = direction.normalized()
animationPlayer.play("Walk1")
if direction == Vector3.ZERO:
animationPlayer.play("KiyugaIdle")
velocity.x = direction.x * speed
velocity.z = direction.z * speed
velocity.y -= fall_acceleration * delta
velocity = move_and_slide(velocity, Vector3.UP)
### FROM A WALK STATE, PLAYER CAN TRANSITION TO SNEAK, HORSE, OR CANOE ###
### THERE ARE NO RESTRICTIONS ###
if Input.is_action_just_released("move_sneak"):
emit_signal("sneaking")
move_state = SNEAK
I'm just not sure how to functionally implement it. Should my horse/canoe be a Rigid Body or Kinematic (or a Rigid in Kinematic mode)? Do I animate the bodies separately and just try really, really hard to get them to sync up? Since I would like to add Horse HP and Canoe Integrity, how would I get them to respawn after X amount of time so that I don't run out of horses or canoes? I feel like the canoe won't be too difficult, but the horse is a little intimidating.