0 votes

Trying to get the mouse move in direction. But I used example from from godot2 to port but didn't work out well. Trying to find the right to get the smoothing to work like the joystick but found there none for mouse when Input.setmousemode(Input.MOUSEMODECAPTURED) is set which fixed the mouse to center. It goes back to zero in different from mouse last position.

extends KinematicBody

var view_sensitivity = 0.10
const ACCEL= 2
const DEACCEL= 4
const MAX_SPEED = 10
slave var slave_vel = Vector3()

export(NodePath) var node_hand_right
export(NodePath) var node_hand_left

var weapon_right
var weapon_left

#var mouse_pos = Vector2()
#var toggle_mouse = false

var last_position = Vector2()

func _ready():
    # Called every time the node is added to the scene.
    # Initialization here
    if node_hand_right != null:
        weapon_right = get_node(node_hand_right)
    if node_hand_left != null:
        weapon_left = get_node(node_hand_left)

#func _process(delta):
#   # Called every frame. Delta is time since last frame.
#   # Update game logic here.
#   pass

func movecheck(delta):
    var dir = Vector3() # Where does the player intend to walk to
    var xform = get_global_transform()

    if Input.is_action_pressed("Up"):
        dir += -xform.basis[2]
    if Input.is_action_pressed("Down"):
        dir += xform.basis[2]
    dir.y = 0
    dir = dir.normalized()
    var hvel = slave_vel
    hvel.y = 0
    var target = dir*MAX_SPEED
    var accel
    if dir.dot(hvel) > 0:
        accel = ACCEL
        accel = DEACCEL
    hvel = hvel.linear_interpolate(target, accel*delta)
    slave_vel.x = hvel.x
    slave_vel.z = hvel.z


func _physics_process(delta):

func _input(event):
    if event.is_action_pressed("Escape"):

    # Print the size of the viewport
    #print("Viewport Resolution is: ", get_viewport().size)
    #print("Mouse Position is: ", get_viewport().get_mouse_position())

    if event is InputEventMouseMotion:
        var delta = event.position - last_position
        last_position = event.position
        #check diff from mouse center drag
        if last_position.x <= 510:
        #if last_position.x <= 511:
            if delta.x < 0:
                self.rotate_y(-delta.x * view_sensitivity)
        if last_position.x >= 512:
        #if last_position.x >= 511:
            if delta.x > 0:
                self.rotate_y(-delta.x * view_sensitivity)

    if event.is_action_pressed("Fire"):
        if weapon_right != null:
            #print("has fun?")
            if weapon_right.has_method("fire"):
                print("found fire")
in Engine by (23 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.