![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | bitdev |
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
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)
$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
else:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
$Cursor/CursorMesh.visible = false`
It will help if you put a test project with minimal setup on github and give the link. Is it possible?
RinAkumetsu | 2023-01-18 21:25
sure 3D Orthogonal Turn-Based RPG v0.1 by Median
bitdev | 2023-01-19 14:51
It says “You do not have access to this page. This game has been restricted by the author and can not be downloaded.” =(
RinAkumetsu | 2023-01-19 14:57
that should do it, try again
bitdev | 2023-01-19 15:54
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.
RinAkumetsu | 2023-01-19 18:20
ok thanks a lot
bitdev | 2023-01-20 01:33
also while youre at it can you help me with the SwipeDetector script? And open the Player At Battle scene
bitdev | 2023-01-20 01:36
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)
RinAkumetsu | 2023-01-20 08:23
can you send me the full code?
bitdev | 2023-01-20 08:37