playMaker

Author Topic: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds  (Read 133 times)

frogwise

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Hey guys,

Just trying to think through how I'm going to setup my Angry Birds-like slingshot mechanic, and I could use your help thinking through the FSM logic.

I have a character who's going to cast a fishing line. I want the player to cast the line by clicking on a spot in the water, dragging backwards, and when they let go, the line shoots out a projectile. The projectile flies at a velocity equivalent to the amount that was pulled back.

I'd like to limit the amount of pull-back that can happen. So for example, if a player clicks at the very top of the "lake" that is furthest back, the pullback amount will cap out at a certain distance.

I also need a way to conver the pull back strength into a velocity amount for a physical projectile.

Thanks in advance for your help :)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 2280
    • View Profile
    • jinxtergames
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #1 on: November 09, 2017, 04:53:56 PM »
Hi,
I have not tried to build something like that yet,
but there is an asset on the asset store which is build with playmaker called Slingshot Playmaker Kit but it seems to be for mobile.

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #2 on: November 09, 2017, 06:49:43 PM »
In pseudo code, something like this in my mind.

Point A, the sling shot. Click and drag back with the mouse. This is point B.

Measure the distance between A and B. Keep checking it on everyframe. Do a float compare. If it is beyond your max distance, take action to not allow the rope to move farther.

Use distance between point A and B to determine velocity. (Add force). Ie, distance * 2 = force. (You will need to see how much force is best for you).

Use two points to determine heading. Normalize the heading to get direction. Apply force when the mouse button is up, in that direction.

frogwise

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #3 on: November 10, 2017, 12:10:42 AM »
Excellent advice!

djaydino - I have looked at Slingshot Kit, but it only offers a 2D solution.

tcmeric - How would I go about drawing the expected trajectory curve? It would need it to go out FURTHER from the "slingshot" as you click-drag your mouse CLOSER to the slingshot. I am struggling with the vector math for this.

tcmeric

  • Sr. Member
  • ****
  • Posts: 480
    • View Profile
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #4 on: November 10, 2017, 09:16:21 AM »
I used this asset: https://www.assetstore.unity3d.com/en/#!/content/55752

I talk about it on my youtube channel, around the 13 minute mark of this video: https://www.youtube.com/watch?v=SH-c1hqdELU&t=748s&spfreload=10

I wrote a custom action to assist for it: https://github.com/dumbgamedev/general-playmaker/tree/master/projectiles/thirdparty

If you watch the video through, it will also show you how I got direction between game objects etc (custom action).

frogwise

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #5 on: November 13, 2017, 09:54:44 PM »
Brilliant, tcmeric! I followed you video and used your actions. I was able to modify the information to fit my needs, but I still need to do some work regarding the "spring loaded" pull-back mechanic to launch the projectile.

Question - I'd like to give my projectile a drag value of 1, so that it doesn't roll infinitely when it lands. However, when I set the rigidbody drag value to 1 and the Projectile Path Prediction 3D linear drag value to 1, I no long hit my "target" object. I get about halfway. This is obvious, since now the object has some drag and will not make it to the target. How can I get around this?

frogwise

  • Playmaker Newbie
  • *
  • Posts: 29
    • View Profile
Re: Creating a spring-loaded launching mechanic in 3D, ala Angry Birds
« Reply #6 on: November 13, 2017, 10:01:38 PM »
I solved this, whether correctly or not, by leaving the DRAG at 0 until I collide with the ground, at which point I then set the DRAG to 1.

Thoughts?