Makin the map movin around my player.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Syl

I’m tryin to make a mini map, and bein under an holed sprite/image, I need my player to stay fixed at the center of the hole, while the map moves around.
Any hints folks?

:bust_in_silhouette: Reply From: Bartosz

I’m not sure what you mean by player staying under hole, but to pin player to center of the screen I would attach camera as a child of player and make sure that cameras drag_margins are disabled or set to 0

here is your script, I change it so map is moved base on mouse position relative to player

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
			" Not sure if this will work."
			$Tween.interpolate_property($Map/Sprite, "global_position", map_pos, map_pos - delta_position, duration, Tween.TRANS_LINEAR, Tween.EASE_IN)

Yes, but the player moves along, and out of view. Ineed it to stay at the center of the hole on the map, beneath my image. As showed here: Imgur: The magic of the Internet

Syl | 2018-03-28 19:54

does image moves with map or does it stay in place together with player?

Bartosz | 2018-03-28 21:11

Sorry, started it anew. T’was too buggy. Here’s the new one, basical, tryin to move the map around my player by mouse click: Imgur: The magic of the Internet

With this script in Node2D root: Imgur: The magic of the Internet Don’t be misguided by ‘Player’ name of the Kinematic, it’s the map, and for the script. The Playeur sprite is the ‘real’ player, supposed to stay pinned in the screen. Notice the - before mouse_pos in tween part. Put it there as the ‘normal’ script was without, and was workin quite fine, but for the inversed direction of the movement. A right click was goin left, and inversely.

So tried that -, but what happen now is that on the first click, wherever it is, the map goes straight to the upper left corner… And I don’t know how to center all that…

Syl | 2018-03-28 22:14

Here’s the goal, with player fixed at the center of the mini map: Imgur: The magic of the Internet

Syl | 2018-03-28 22:39

I think I get it now. You could try 4 different approaches depending how you implemented rest of your logic:
1.Simples - attach sprite with hole as a parent of player - this way it will be glued to player
2. Use camera offset property to set center of camera to not be directly over player e.g if hole is 100px to the right and 200 px to top of center of screen offset would be (100,-200)
3. Use vieport. It is harder but may come handy in the future. Basically you create to scene: one with sprite and hole and secon with player and map. In the scene with hole you create vieport and sprite to render it and place it directly below hole check my demo at godot-recipes
4. You create script that manually position player and hole every frame.

Bartosz | 2018-03-29 19:32

1.Map/sprite(corrected it from Player/sprite) is not found with hole sprite as parent.
2.Still that rush in the lowerleft corner.
3.Lil bugs: Imgur: The magic of the Internet But tryin to make it for my project. Though that tinkerin seems really hopeless…
4.Not for my level…

Btw, got another helper on godot forum, see what he says: Loading...

I’m Johyn there.

Syl | 2018-03-29 20:48

About the character creation recipe, can’t we just use buttons in the stead of scripts?

Syl | 2018-03-29 21:25

Yes it is possible to use buttons. I’m using script just because I’m lazy, and prefer when program automatically generate ui based on my data.
Off topic:
Syl could you look on this question and notify someone on forum about it?

Bartosz | 2018-03-29 21:51

That’s good timin, as the helper I told you about, is a moderator. He’s notified now.
Butons are not easier and faster to use, even if you know scriptin?

Syl | 2018-03-29 22:04

Placing buttons in editor is definitively faster and easier. But when you try to make ui for things that are very fluid during development it becomes real PIA.

As rule of thumb:

  • simple thinks or ones that never change - create ui in editor
  • very dynamic data or data that will change during game development a lot - use script
  • something in between - create in editor “template” of ui and then extend/fill it in script

At least this is what I’m doing

Bartosz | 2018-03-29 22:19

I see, and butons are not generatin their scripts somewhere? Are they heavier than usin GDS?

Syl | 2018-03-29 22:38

Buttons are not heavier. In terms of resources it really doesn’t matter whether you creates your gui in editor or by generating in script.

Bartosz | 2018-03-29 23:03

Okokok. I’ll see with time.

Syl | 2018-03-29 23:21

check my updated answer it contains modified script from your game

Bartosz | 2018-03-31 15:28

Man! That works perfectly!
That won’t be a special mention, but credited as THE game designer! :wink:

Syl | 2018-03-31 15:54