I followed a tutorial by PlugWorld for a lot of the stuff (also many other tutorials) and then changed some stuff myself...
it is meant to be a script for a kinematicbody to work for online stuff and the animations and rotation does not work (ik why the animations don't work though so only worry about the rotation) here is the script:
extends KinematicBody
onready var sprite = $Head/shroomhuman
signal health_updated(health)
signal killed()
var jumping = false
var walking = false
var attacking = false
var idle = true
var walk_speed := 15.0
var jump_speed := 15.0
var acceleration_speed := 10.0
var gravity := -20.0
var moving = false
export (float) var max_health = 100
var puppet_position = Vector3()
var puppet_velocity = Vector3()
var puppet_rotation = Vector3()
onready var health = max_health setget _set_health
onready var inv_timer = $inv_timer
var _dir := Vector3.ZERO
var _vel := Vector3.ZERO
onready var _camera := $Head
export(NodePath) onready var head = get_node(head) as Spatial
export(NodePath) onready var model = get_node(model) as Spatial
export(NodePath) onready var camera = get_node(camera) as Camera
export(NodePath) onready var network_tick_rate = get_node(network_tick_rate) as Timer
export(NodePath) onready var movement_tween = get_node(movement_tween) as Tween
export(NodePath) onready var anim = get_node(anim) as AnimationPlayer
func do_anim():
if moving:
print("moving true")
if walking and not attacking and not jumping:
anim.play("Run")
elif attacking and not jumping and not walking:
anim.play("Attack")
elif jumping and not walking and not attacking:
anim.play("Jump")
else:
anim.play("Run")
elif idle and not moving:
anim.play("Idle")
else:
anim.play("Idle")
print("ur code isnt rlly working if it is this")
func _ready():
camera.current = is_network_master()
func _physics_process(delta: float) -> void:
if is_network_master():
var input := Vector2.ZERO
if Input.is_action_pressed("move_forward"):
moving = true
walking = true
attacking and jumping and idle == false
anim.play("Run")
input.y += 1
if Input.is_action_pressed("move_backward"):
moving = true
walking = true
attacking and jumping and idle == false
anim.play("Run")
input.y -= 1
if Input.is_action_pressed("move_right"):
moving = true
walking = true
attacking and jumping and idle == false
anim.play("Run")
input.x += 1
if Input.is_action_pressed("move_left"):
moving = true
walking = true
attacking and jumping and idle == false
anim.play("Run")
input.x -= 1
if Input.is_action_just_pressed("Attack"):
damage(30)
attacking = true
walking and jumping and idle == false
print(health)
moving = true
anim.play("Attack")
input = input.normalized()
if Input.is_action_just_released("Attack"):
attacking = false
if walking and jumping == false:
idle = true
moving = false
if Input.is_action_just_released("move_backward"):
walking = false
if attacking and jumping == false:
idle = true
moving = false
if Input.is_action_just_released("move_forward"):
walking = false
if attacking and jumping == false:
idle = true
moving = false
if Input.is_action_just_released("move_left"):
walking = false
if attacking and jumping == false:
idle = true
moving = false
if Input.is_action_just_released("move_right"):
walking = false
if attacking and jumping == false:
idle = true
moving = false
if moving == false:
anim.play("Idle")
if is_on_floor():
if Input.is_action_just_pressed("jump"):
anim.play("Jump")
walking and attacking and idle == false
jumping = true
_vel.y = jump_speed
moving = true
if Input.is_action_just_released("jump"):
moving = false
jumping = false
if walking and jumping == false:
idle = true
var basis: Basis = _camera.global_transform.basis
_dir = Vector3.ZERO
_dir += -basis.z * input.y
_dir += basis.x * input.x
_dir = _dir.normalized()
else:
global_transform.origin = puppet_position
_vel.x = puppet_velocity.x
_vel.z = puppet_velocity.z
head.rotation.y = puppet_rotation.y
_vel.y += gravity * delta
var acc := _vel.linear_interpolate(_dir * walk_speed, acceleration_speed * delta)
if !movement_tween.is_active():
_vel = move_and_slide(Vector3(acc.x, _vel.y, acc.z), Vector3.UP)
puppet func update_state(p_positon, p_velocity, p_rotation):
puppet_position = p_positon
puppet_velocity = p_velocity
puppet_rotation = p_rotation
movement_tween.interpolate_property(self, "global_transform", global_transform, Transform(global_transform.basis, p_positon), 0.1)
movement_tween.start()
do_anim()
func damage(amount):
#add armour damage reduction later
#also pvp disable and enable
if inv_timer.is_stopped():
inv_timer.start()
_set_health(health - amount)
func kill():
if is_network_master():
get_tree().change_scene("res://scenes/dead.tscn")
func _set_health(value):
if is_network_master():
var prev_health = health
health = clamp(value, 0, max_health)
if health != prev_health:
emit_signal("health_updated", health)
if health == 0:
kill()
emit_signal("killed")
func _on_NetworkTickRate_timeout():
if is_network_master():
rpc_unreliable("update_state", global_transform.origin, _vel, Vector2(head.rotation.y, rotation.x)) #this was originally head.rotation.x and rotation.y
else:
network_tick_rate.stop()
if you can figure out why rotation does not work thanks!
edit: I AM IDIOT AND JUST NEEDED TO SWAP THE FIRST THING IN THE VECTOR WITH THE SECOND THING LOL