About 'Adding Objective Markers'!

In this video (objectives)…

1 Create a visual objective marker 2 Move that visual marker to a new position when needed

After watching (learning outcomes)…

Understand how and when to use Tween nodes and use a parent node as an array

(Unique Video Reference: 35_HM_GDT)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

A few tweaks I made:

  1. I started the objective marker at the same location as the player, so the marker moves from the player to the first objective when the tutorial starts, instead of swooping in from some unrelated area of the screen.
    ObjectiveMarkers

  2. I didn’t like the “objective met” sound being played when the tutorial starts, so I moved the $AudioStreamPlayer.play() out of the function that moves the objective pointer and into the function that gets called when the objective area is entered. That way the sound plays when the objective areas are entered, but not when _ready moves the pointer to the first location.

  3. Since all of the objective areas do the same thing, I connected all of the Area2D signals to the same function.

  4. I found that I was playing my own tutorial badly and accidentally backstepping and entering one of the previously-met objective areas again. This caused the objective pointer to advance anyway and eventually caused me to run out of objective markers and fail on $ObjectiveMarkers.get_child(0). I followed the same trick as with the objective markers and remove the first child of $ObjectiveAreas whenever an area is entered. This does mean that I have to be careful to put the areas in the correct order in the scene, otherwise I will be removing the wrong one.

My final code looks like this:

extends Node2D


func _ready():
	$ObjectivePointer.position = Global.Player.position
	move_objective_pointer()


func move_objective_pointer():
	var pointer = $ObjectivePointer
	var marker = $ObjectiveMarkers.get_child(0)
	$Tween.interpolate_property(pointer, "position", pointer.position, marker.position, 
			1.2, Tween.TRANS_SINE, Tween.EASE_IN_OUT)
	$Tween.start()
	$ObjectiveMarkers.remove_child(marker)


#All objective areas connect to this function
func _on_ObjectiveArea_body_entered(body):
	move_objective_pointer()
	$AudioStreamPlayer.play()
	var area = $ObjectiveAreas.get_child(0)
	$ObjectiveAreas.remove_child(area)
2 Likes

That code works great and makes alot of sense. Thanks @DanielMcPherson

@Yann_Burrett, in this video as well as in several of the prior videos you state you do not like to duplicate Area2D’s which have a CollisionShape2D as a child. The reason being, doing so would necessitate to recreate the CollisionShape2D.

However, this is not entirely true. Or at least not in the sense of having to delete a CollisionShape2D and manually adding a new one. I am not sure whether you have possibly already gotten to learn this or not. And if so, it might still be of value for others.

When selecting the CollisionShape2D, click on the little downward arrow next to the actual shape and select “Make Unique”. By doing this, Godot has got you covered. Your Area2D now has its own, unique CollisionShape2D and you are free to alter its size without affecting the Area2D you duplicated it from.

Privacy & Terms