Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Dragon20C |
I have some simple scripts I want to be able to change the players facing position when I press the up key and the camera is a different position I want the player to change to that direction!
This is my player script:
extends KinematicBody
var velocity = Vector3(0,0,0)
const speed = 8
var gravity = Vector3.DOWN * 12
var jump = false
func _ready():
pass
func _physics_process(delta):
get_input()
move_and_slide(velocity, Vector3.UP)
velocity += gravity * delta #Adds gravity to the player
if jump and is_on_floor():
velocity.y = 10
jump = false
func get_input():
if Input.is_action_pressed("Move Up") and Input.is_action_pressed("Move Down"):
velocity.z = 0
elif Input.is_action_pressed("Move Up"):
velocity.z = -speed
elif Input.is_action_pressed("Move Down"):
velocity.z = +speed
else:
velocity.z = lerp(velocity.z, 0, 0.2)
if Input.is_action_pressed("Move Left") and Input.is_action_pressed("Move Right"):
velocity.x = 0
elif Input.is_action_pressed("Move Left"):
velocity.x = -speed
elif Input.is_action_pressed("Move Right"):
velocity.x = +speed
else:
velocity.x = lerp(velocity.x, 0, 0.2)
if Input.is_action_just_pressed("Jump"):
jump = true
This is my Camera script
extends Spatial
var rotation_speed = 0.09
var max_zoom = 3.0
var min_zoom = 0.5
var zoom = 1.5
var zoom_speed = 0.09
func _ready():
pass
func _physics_process(delta):
$InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x, -1.4, 0.1)
scale = lerp(scale, Vector3.ONE * zoom, zoom_speed)
func _unhandled_input(event):
if event is InputEventMouseMotion and Input.is_action_pressed("Right_Mouse_Button"):
rotate_y(deg2rad(-event.relative.x * rotation_speed))
if event is InputEventMouseMotion and Input.is_action_pressed("Right_Mouse_Button"):
$InnerGimbal.rotate_x(deg2rad(-event.relative.y * rotation_speed))
if event.is_action_pressed("zoom_in"):
zoom -= zoom_speed
if event.is_action_pressed("zoom_out"):
zoom += zoom_speed
zoom = clamp(zoom, min_zoom, max_zoom)