I am creating a boss fight in which enemy does melee attacks if he is near player and throw his sword towards the player if they are far.
I am trying to do the following:
The sword will be thrown towards the player to attack him, and the sword will then come back to the enemy like a boomerang so that he can attack again. So, the sword will come back to the enemy in both situations whether the player gets hit or not.
I tried using physics behavior and add force actions but either the sword doesn’t move or the movement is not what I want.
I saw there is a boomerang behavior as well. I don’t know how to use it but I read the documentation and tried it. I don’t know if there is a bug in the behavior, but the sword starts glitching and goes upwards instead of towards the player. I think there is some bug in the behavior. So I tried many methods but none of them worked.
I want to use a less complicated way that is beginner-friendly and does the job.
If there are multiple ways to do it, I would like to try them and then pick what suits my game.
Also I want to add a spin animation to the sword when its thrown and then change/flip the direction when it is coming back to the enemy. How will I integrate this with the Sword throw/boomerang logic?
Also do I need any behavior like platformer object, physics etc on the sword? As you can see in the screenshot, the enemy (pirate guy) just throws a sword but it is just lying on ground doing nothing. It doesn’t even hit the king. Not going back to enemy and even if enemy touches it, it still doesn’t get deleted. So, what could be the problem?
I just would like to encourage you to use the boomerang behavior again. Just because something is not working the way you think it should, it isn’t automatically a bug. It is a bit tricky to get the behavior to work though.
My guess is that you missed this part as stated in the documentation: “Run the “Track location of thrower” action every frame so the boomerang returns correctly”
I have tried this and it works (it creates the sword by left mouse click and deletes it, when it is returning to the thrower and in 10 px distance):
If you want to make your own boomerang mechanic you could check also this older video tutorial.
The explanation is not in English but you can still follow along or get some inspiration for your own events. Since the tutorial is a bit older, there may be some things different in the current Gdevelop version.
Your guess was right. I missed the “Track location of thrower” action to run every frame. I misunderstood it as not adding the “Trigger Once” condition to make it run every frame. However, the problem still hasn’t completely resolved. The sword is being thrown up in the air. Like it diagonally goes upwards. I want it to be thrown straight and if not straight then at least along x-axis so that the attack towards king can be made.
Also, how do i change the direction of sword and add spin animation that my sword sprite already has while using boomerang behavior? The sword should also flip according to the how enemy is facing player king.
In your case, throwing it straight means actually along the x-axis, no? There is an action in the boomerang behavior ‘Throw boomerang toward an angle’. 0 degree is straight on the x-axis to the right, and 180 degree straight to the left.
The behavior is doing this for you. In the behavior menu or in the events you set the amount of pixels the boomerang-object is flying per second and how many seconds you want it to fly before it returns back to the thrower. So this sets the distance and speed of your boomerang. You have to try a bit to find the right values for your game.
The boomerang behavior is doing this for you as well. You can set the rotation degrees per second. If you have a special animation which you want to play instead of just rotating the sword, you set the rotation value in the event to 0 and then you have to find a way to change the sword animation. I would use a boolean variable (e.g. boomerang = false) which is toggled when the boomerang throw is activated. Based on the state of the variable you can change the animation (e.g. condition: boomerang = true; action: change the animation of sword to ‘fly’).
Thanks for replying. I will try to make it work using your tips. Also, one thing that you misunderstood (I think I didn’t explain well) is that by changing the direction of sword sprite I meant flipping of the sprite so that the hilt and blade are facing the person it’s been thrown at and then when it goes back to the thrower that time also the hilt/blade should face him so that the process looks smooth (imagine a sword being thrown as a boomerang). Currently, the sword’s blade is facing right so if the attack is made on left side (sword thrown on left) the attack looks weird because the blade is facing right.
I read that in your initial post and I did not address it because I wanted to let you know first that the boomerang behavior is working and that you should try it again.
Alright, so can you throw your sword and does it return to the thrower? Is it rotating? I am asking because this may help to solve the other problems.
This is tricky to understand because if I imagine that someone throws a sword, the blade point is facing the opponent first and not the hilt - or do you talk about the sword when it is flying and rotating?
If you mean the sword is rotating, this is exactly what the boomerang behavior does (unless you set 0 or a very small number in the “angle - degrees” field).
There is a flip-action. In case your king enemy is moving around and/or turning towards your player, you also can just flip the sword (supposed the king is holding it).