I am trying to make a game with SpriteKit where the main character shoots a 'rope' and swings through the level (Think spiderman-ish). I have no problem making the rope and having it attached to the player and different sprites but I don't really know how to go about the 'shooting' part.
My current rope is built similar to this (https://www.youtube.com/watch?v=7jWdcbmnmKQ&hd=1) where I have several separate parts connected using SKPhysicsJointPin
. I have tried several different approaches to shoot the rope, both with applyImpulse/Force
and SKActions
, but none works smoothly.
To sum it up:
- What is best practice for creating a rope that can extend in a specific direction?
I'm fine with just general pointers in the right direction since this is all to learn and I don't think I really need completed code for it.
General pointer:
In theory this should extend the rope while shooting, without affecting the trajectory of the bullet.
You may need to add more rope segments as the distance between the bullet and the weapon/player increases, otherwise the rope may be huddled too tightly together at the start of the bullet's flight path, causing physics to behave unexpectedly. Though adding rope segments in-flight may cause issues in its own right.
One solution could be to disable physics for the rope until a certain distance has been reached or the bullet "hit" something. Until then the rope could be considered a straight line and rope segment nodes positioned accordingly along a straight line between bullet and weapon.