This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

So I was recently creating a drag and move mechanic in my game and it was successful.
Then I just wanted to make the player look at the cursor with:

look_at(Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0)

and it works...

However when I tested the game, the player suddenly doesn't go in the direction of the mouse; atleast some certain directions. When I removed the look_at() function, it definitely works... Can you help me please?

The function:
var space_state = get_world().direct_space_state

var mouse_position = get_viewport().get_mouse_position()
var cursor_pos = Vector3()

rayOrigin = camera.project_ray_origin(mouse_position)
rayEnd = rayOrigin + camera.project_ray_normal(mouse_position) * 20000

var intersection = space_state.intersect_ray(rayOrigin, rayEnd)

if not intersection.empty():
    var pos = intersection.position

    $Cursor/CursorMesh.visible = true
    look_at(Vector3(pos.x, translation.y, pos.z), Vector3(0, 1, 0))
    if Input.is_action_pressed("click"):
        var point = Vector3(pos.x, translation.y, pos.z)
        direction = point - transform.origin
        motion = direction.normalized()
        motion += transform.basis * direction
    $Cursor/CursorMesh.visible = false`
Godot version 3.5.1.stable
in Engine by (15 points)
edited by

It will help if you put a test project with minimal setup on github and give the link. Is it possible?

It says "You do not have access to this page. This game has been restricted by the author and can not be downloaded." =(

that should do it, try again

Ok, what do you want to achieve with the motion += transform.basis * direction line? Because if you remove that line and just set motion to motion = direction.normalized() or motion = direction, a player moves to the right direction already.

ok thanks a lot :D

also while youre at it can you help me with the SwipeDetector script? And open the Player At Battle scene

First of all you have to enable "emulate touch from mouse" property in project settings. Then there is a strange logic how you determine the end of touch. Try this: func _input(event): if not event is InputEventScreenTouch: return if event.is_pressed(): _start_detection(event.position) else: _end_detection(event.position)

can you send me the full code?

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 Frequently asked questions and 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 [email protected] with your username.