Godot Gdscript-更改相机方向时,如何使播放器向前移动?

问题描述

快速免责声明我对gdscript的了解最少,我了解python,但我也听说过类似的内容,但是如果您将其愚弄了,不胜感激!并简单地解释一下,谢谢!

我希望播放器根据侧轴上的摄像头移动来更改方向,因此,如果将摄像头向左移动并按前进键,则希望播放器沿该方向移动。

在我的“游戏”中,我有一个照相机和一个播放器脚本,它们看起来像这样。

extends KinematicBody

var gravity = Vector3.DOWN * 10
var speed = 6
var jump = false
var velocity = Vector3.ZERO


func _physics_process(delta):
    velocity += gravity * delta
    get_input(delta)
    velocity = move_and_slide(velocity,Vector3.UP)
    if jump and is_on_floor():
        velocity.y = 10
        
func get_input(delta):
    var vy = velocity.y
    velocity = Vector3()
    if Input.is_action_pressed("up"):
        velocity += -transform.basis.z * speed
    if Input.is_action_pressed("down"):
        velocity += transform.basis.z * speed
    if Input.is_action_pressed("left"):
        velocity += -transform.basis.x * speed
    if Input.is_action_pressed("right"):
        velocity += transform.basis.x * speed
    if Input.is_action_pressed("camera right"):
        rotate_y(-0.06)
    if Input.is_action_pressed("camera left"):
        rotate_y(+0.06)

    velocity.y = vy
    jump = false
        
    if Input.is_action_just_pressed("jump"):
        jump = true
#func _unhandled_input(event):
    #if event is InputEventMouseMotion: #and Input.is_action_pressed("Right_Mouse_Hold")
        #transform.basis = Basis(Vector3(1,0),PI) * transform.basis

现在还有相机

extends Spatial

export var rotation_speed = PI/2
export var max_zoom = 3.0
export var min_zoom = 0.5
export var zoom_speed = 0.09


var mouse_control = true
var mouse_sensitivity = 0.005
var zoom = 1.5



func _process(delta):
    get_input_keyboard(delta)
    $InnerGimbal.rotation.x = clamp($InnerGimbal.rotation.x,-1.4,0.6)
    scale = lerp(scale,Vector3.ONE * zoom,zoom_speed)
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _unhandled_input(event):
    if mouse_control and event is InputEventMouseMotion:
        if event.relative.x != 0 and Input.is_action_pressed("Right_Mouse_Hold"):
            rotate_object_local(Vector3.UP,-event.relative.x * mouse_sensitivity)
        if event.relative.y != 0 and Input.is_action_pressed("Right_Mouse_Hold"):
            var y_rotation = clamp(event.relative.y,-30,30)
            $InnerGimbal.rotate_object_local(Vector3.RIGHT,-y_rotation * mouse_sensitivity)
    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)
    print(rotation)
func get_input_keyboard(delta):
    if Input.is_action_pressed("quit"):
        get_tree().quit()

在相机中,我跟随着一个tut,该tut包含两个空间节点,一个控制y轴,另一个控制x(不确定我是否在谈论正确的轴)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)