#How to make a combat system like game endeavour's zoe and the cursed dreamer?
1 messages · Page 1 of 1 (latest)
At a high level, here's what I'd do:
- Make a new node type, derived from Node2D. Lets call it SwordSwinger.
- Add a SwordSwinger node as a child of your player character, at local position 0,0.
- In SwordSwinger._Process function, I would use Transform.LookAt() to point the node at the mouse cursor.
- Add a sword sprite as a child of the SwordSwinger.
- Position the sprite so the base of the sword handle is SwordSwinger's 0,0 coordinate
- Rotate the sprite so that the point aims in the direction that SwordSwinger faces when you call its LookAt() function.
Now you have a sword that always points at your mouse cursor!
Next add a function on SwordSwinger that rotates the sword node sprite locally from -45 degrees to +45 degrees. This rotation is easy to calculate because its local. You'll get the real in game roation for free when the parent (SwordSwinger) rotates using the LookAt() function.
You can pull off the rotation easily with a tween, something like this pseudocode:
sprite.rotation_degrees = -45
tween = GetTree().CreateTween()
tween.tween_property(sprite, "rotation_degrees" -45, 0.05)
tween.chain().tweenProperty(sprite, "rotation_degrees" 45, 0.5)
tween.chain().tweenProperty(sprite, "rotation_degrees" 0, 0.05)
Trigger this on a button press, and presto!
But what about collisions?
Restructure your SwordSwinger tree like so:
Setup CollisionSHape2D to match the sword sprite and hook up the area2Ds signals to the character node.
Now if you rotate the Node2D instead of the sword, the collider moves with it.
thanks i will try that out now
i did try it but the tween.chain() lines didnt seem to work and also need to figure out how to flip the players h whenever your facing your mouse to the right or left. Sorry if i didnt explain that very well