Hello,
I am trying to find the error in this script which is attached to my player, I am following step by step a video course but I can't identify the issue.
I'm attaching the full script, please help!!
Thanks a lot in advance! :)
ERROR MESSAGE: Invalid type in function 'moveandslide' in base 'KinematicBody (PlayerController.gd)'. Cannot convert argument 1 from float to Vector3.
extends KinematicBody
Declare member variables here. Examples:
var a = 2
var b = "text"
var velocity = Vector3 (0,0,0)
var y_velocity = velocity.y
export (float, 0 , 100) var WALK = 5.0
export (float, 0 , 100) var RUN = 12.5
export (float, 0 , 100) var GRAV = 9.8
export (float, 0 , 100) var JUMP = 7.0
export (float, 0 , 100) var ANGLE = 0.0000001
export (float, 0 , 100) var ZOOM = 1.0
Called when the node enters the scene tree for the first time.
func ready():
#pass # Replace with function body.
#Lock cursor to the game window
Input.setmousemode(Input.MOUSEMODE_CAPTURED)
func input(event):
if Input.isactionpressed("scrollup"):
$Spatial/Camera.translate(Vector3(0 , 0.5 * -ZOOM , -ZOOM))
if Input.is_action_pressed("scroll_down"):
$Spatial/Camera.translate(Vector3(0 , 0.5 * ZOOM , ZOOM))
func unhandledinput(event):
if event is InputEventMouseMotion:
rotate_y(-lerp(0, ANGLE, event.relative.x/10))
func handleinput ():
#Save yvelocity of the player before makinng changes to the local transform
y_velocity = velocity.y
#Reset the player's velocity to detect new changes to player's movement
velocity = Vector3(0, 0, 0)
if Input.is_action_pressed("ui_right") and Input.is_action_pressed("ui_left"):
velocity = 0
elif Input.is_action_pressed("ui_right"):
if Input.is_action_pressed("ui_shift"):
velocity = RUN * transform.basis.x
else:
velocity = WALK * transform.basis.x
elif Input.is_action_pressed("ui_left"):
if Input.is_action_pressed("ui_shift"):
velocity = -RUN * transform.basis.x
else:
velocity = -WALK * transform.basis.x
else:
velocity = 0
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
velocity = 0
elif Input.is_action_pressed("ui_up"):
if Input.is_action_pressed("ui_shift"):
velocity = -RUN * transform.basis.z
else:
velocity = -WALK * transform.basis.z
elif Input.is_action_pressed("ui_down"):
if Input.is_action_pressed("ui_shift"):
velocity = RUN * transform.basis.z
else:
velocity = WALK * transform.basis.z
else:
velocity = 0
#Restore y_velocity of the player after making changes to the local transform
velocity = y_velocity
if Input.is_action_pressed("ui_select") and is_on_floor():
velocity.y = JUMP
if Input.is_action_pressed("ui_cancel"):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
#The $ Symbol is as get_node() function.
#Write get_noce(Spatial).rotate_y(deg2rad(-ANGLE)) works too
if Input.isactionpressed("Q"):
$Spatial.rotate_y(deg2rad(-ANGLE))
#
if Input.isactionpressed("E"):
$Spatial.rotate_y(deg2rad(ANGLE))
func physicsprocess(delta):
if not isonfloor():
velocity.y -= GRAV * delta
handle_input()
move_and_slide(velocity , Vector3.UP)