Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Syl |
Greets!
Got my player/sprite on minimap movin freely, but my area2D/collisionshape2D don’t detect their collision. When a key moved sprite/player is detected.
How to make it for mouse controlled please?
I’m not sure I undestrood, can you be more specific?
DodoIta | 2018-04-04 13:05
Well, I’ve got a mini map, with a Player/sprite movin on it, triggerin scenes changes with area2D collisions. But that works only when my player/sprite is moved through the keyboard. When movin with the mouse, as I intend it to be, the area2Ds don’t detect my sprite/player anymore.
Here’s my code for mouse movement:
extends Node2D
var terrain_speed = 1.0
var speed = 3*50 # triple speed
var first_input = false
func _input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
var map_pos = $Map/Sprite.global_position
var mouse_pos = get_global_mouse_position()
var delta_position = mouse_pos - $Player.global_position # mouse click relative to player sprite
var distance = map_pos.distance_to(mouse_pos)
var duration = distance * terrain_speed/speed
if first_input == false:
first_input = true
$Tween.interpolate_property($Map/Sprite, "global_position", map_pos, map_pos - delta_position, duration,
Tween.TRANS_LINEAR, Tween.EASE_IN)
$Tween.start()
return
And here’s the scene, to give you an idea:
Imgur: The magic of the Internet
Syl | 2018-04-04 13:30