I'm trying to add camera rotation to my character in Godot, but I keep getting the error "Invalid call to function 'rotated' in base 'Vector3'.Expected 2 arguments" i tried making the direction variable a vector 2, but when i did that the physics function that makes my bean character jump, will not work because there has to be another axis that it can move on code: (error is from line 58)
extends KinematicBody
var damage = 10
var speed = 500
var direction = Vector3()
var gravity = -9.8
var velocity = Vector3()
var sens = 0.2
onready var cam = get_node("Camera")
onready var anim_player = $AnimationPlayer
onready var camera = $Camera
onready var raycast = $Camera/RayCast
func _ready():
print("hi")
func _input(event):
if event is InputEventMouseMotion:
var movement = event.relative
cam.rotation.x += -deg2rad(movement.y * sens)
cam.rotation.x = clamp(cam.rotation.x, deg2rad(-45), deg2rad(180))
rotation.y += -deg2rad(movement.x * sens)
func fire():
if Input.is_action_pressed("Fire"):
if not anim_player.is_playing():
if raycast.is_colliding():
var target = raycast.get_collider()
if target.is_in_group("enemy"):
target.health -=damage
anim_player.play("AssaultRifleFire")
else:
anim_player.stop()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
fire()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if Input.is_key_pressed(KEY_ESCAPE):
get_tree().quit()
direction = direction.normalized().rotated(-rotation.y)
direction = Vector3(0, 0, 0)
if Input.is_action_pressed("Left"):
direction.z -= 1
if Input.is_action_pressed("Right"):
direction.z += 1
if Input.is_action_pressed("Forward"):
direction.x += 1
if Input.is_action_pressed("Back"):
direction.x -= 1
direction = direction.normalized()
direction = direction * speed * delta
if velocity.y > 0:
gravity = -20
else:
gravity = -30
velocity.y += gravity * delta
velocity.x = direction.x
velocity.z = direction.z
velocity = move_and_slide(velocity, Vector3(0, 1, 0))
if is_on_floor() and Input.is_key_pressed(KEY_SPACE):
velocity.y = 10
var speed = 500
var direction = Vector3()
var gravity = -9.8
var velocity = Vector3()
var sens = 0.2
onready var cam = get_node("Camera")
onready var anim_player = $AnimationPlayer
onready var camera = $Camera
onready var raycast = $Camera/RayCast
func _ready():
print("hi")
func _input(event):
if event is InputEventMouseMotion:
var movement = event.relative
cam.rotation.x += -deg2rad(movement.y * sens)
cam.rotation.x = clamp(cam.rotation.x, deg2rad(-45), deg2rad(180))
rotation.y += -deg2rad(movement.x * sens)
func fire():
if Input.is_action_pressed("Fire"):
if not anim_player.is_playing():
if raycast.is_colliding():
var target = raycast.get_collider()
if target.is_in_group("enemy"):
target.health -=damage
anim_player.play("AssaultRifleFire")
else:
anim_player.stop()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
fire()
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if Input.is_key_pressed(KEY_ESCAPE):
get_tree().quit()
direction = direction.normalized().rotated(-rotation.y)
direction = Vector3(0, 0, 0)
if Input.is_action_pressed("Left"):
direction.z -= 1
if Input.is_action_pressed("Right"):
direction.z += 1
if Input.is_action_pressed("Forward"):
direction.x += 1
if Input.is_action_pressed("Back"):
direction.x -= 1
direction = direction.normalized()
direction = direction * speed * delta
if velocity.y > 0:
gravity = -20
else:
gravity = -30
velocity.y += gravity * delta
velocity.x = direction.x
velocity.z = direction.z
velocity = move_and_slide(velocity, Vector3(0, 1, 0))
if is_on_floor() and Input.is_key_pressed(KEY_SPACE):
velocity.y = 10