2D: Throw spear, stick spear to enemy, pick up spear

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

Dear community,

I am working on a gory 2D sprite based hack and slash sidescroller. I already figured out how to paint wails / ceilings / floors with blood texture and how to implement blood particles.

One thing I can’t get my mind around is how I would achieve something like throwing a spear which collides with the enemy, sticks where it hit the enemy sprite and once the enemy dies can be collected by the player again.

This is basically two problems in one:

  • How to have items with physics that the player can hold, throw and collect (swords, flashbangs, spears, arrows, whatever)
  • How to make something attach to an enemy sprite

I am happy about any suggestion where to look for a solution or which tutorial to watch.

:bust_in_silhouette: Reply From: BakouKai

Hi,

I am not very experienced on godot and coding in general but here are my two cents on your questions :

  • Throwing a spear is basically like shooting with a gun. There are many tutorials with this (shooting guns). I would instantiate an object with a collisionbody and a trajectory. When you throw, your character sprites change to spearless (I would required a set of sprite with and without spear).

  • When it collide with the enemy , you can get the coordinates and plant a spear as collectable there. Or change your enemy sprite to a “pined sprite with a spear on it” that would provide the player with a new spear if the player collides with it.

It may be suboptimal but that would be the way for me to do it.

Sorry for the poor english though, I feel sleepy :smiley:

I really like the logic you came up with, my thoughts on the topic were way more complicated. Thank you!

ThreeOax | 2021-03-31 07:03