playMaker

Author Topic: Changing script to playmaker States.  (Read 3109 times)

bartas

  • Playmaker Newbie
  • *
  • Posts: 9
Changing script to playmaker States.
« on: March 02, 2015, 03:09:34 PM »
Hello,

I've watched Unity Angry Birds tutorial , I've mostly understand the logic and the script but when I tried to do the same with playmaker I got stuck. When I tried to follow tutorial (http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/making-angry-birds-style-game) , I had no idea from what I should have  start , when I typed in action line renderer , I coudn't find anything.
If someone would be kind enough to give me small steps to do this  I'd be grateful.

The scipt :
Code: [Select]
using UnityEngine;

public class ProjectileDragging : MonoBehaviour {
public float maxStretch = 3.0f;
public LineRenderer catapultLineFront;
public LineRenderer catapultLineBack; 

private SpringJoint2D spring;
private Transform catapult;
private Ray rayToMouse;
private Ray leftCatapultToProjectile;
private float maxStretchSqr;
private float circleRadius;
private bool clickedOn;
private Vector2 prevVelocity;


void Awake () {
spring = GetComponent <SpringJoint2D> ();
catapult = spring.connectedBody.transform;
}

void Start () {
LineRendererSetup ();
rayToMouse = new Ray(catapult.position, Vector3.zero);
leftCatapultToProjectile = new Ray(catapultLineFront.transform.position, Vector3.zero);
maxStretchSqr = maxStretch * maxStretch;
CircleCollider2D circle = collider2D as CircleCollider2D;
circleRadius = circle.radius;
}

void Update () {
if (clickedOn)
Dragging ();

if (spring != null) {
if (!rigidbody2D.isKinematic && prevVelocity.sqrMagnitude > rigidbody2D.velocity.sqrMagnitude) {
Destroy (spring);
rigidbody2D.velocity = prevVelocity;
}

if (!clickedOn)
prevVelocity = rigidbody2D.velocity;

LineRendererUpdate ();

} else {
catapultLineFront.enabled = false;
catapultLineBack.enabled = false;
}
}

void LineRendererSetup () {
catapultLineFront.SetPosition(0, catapultLineFront.transform.position);
catapultLineBack.SetPosition(0, catapultLineBack.transform.position);

catapultLineFront.sortingLayerName = "Foreground";
catapultLineBack.sortingLayerName = "Foreground";

catapultLineFront.sortingOrder = 3;
catapultLineBack.sortingOrder = 1;
}

void OnMouseDown () {
spring.enabled = false;
clickedOn = true;
}

void OnMouseUp () {
spring.enabled = true;
rigidbody2D.isKinematic = false;
clickedOn = false;
}

void Dragging () {
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 catapultToMouse = mouseWorldPoint - catapult.position;

if (catapultToMouse.sqrMagnitude > maxStretchSqr) {
rayToMouse.direction = catapultToMouse;
mouseWorldPoint = rayToMouse.GetPoint(maxStretch);
}

mouseWorldPoint.z = 0f;
transform.position = mouseWorldPoint;
}

void LineRendererUpdate () {
Vector2 catapultToProjectile = transform.position - catapultLineFront.transform.position;
leftCatapultToProjectile.direction = catapultToProjectile;
Vector3 holdPoint = leftCatapultToProjectile.GetPoint(catapultToProjectile.magnitude + circleRadius);
catapultLineFront.SetPosition(1, holdPoint);
catapultLineBack.SetPosition(1, holdPoint);
}
}

Thank you for your help.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Changing script to playmaker States.
« Reply #1 on: March 03, 2015, 09:00:58 AM »
Hi,

 this is quite a script and would take time to port to PlayMaker. Can you bump me in 2 weeks if you haven't had other members step in or found a solution?
 
I see a way to combine arrayMaker here so that you can give a list of points or gameobjects and then the action would automatically connect the gameobjects.

 also check out Vectrosity, it does a lot towards what you want to achieve.

Thanks,

 jean

bartas

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Changing script to playmaker States.
« Reply #2 on: March 03, 2015, 12:09:16 PM »
Thank you Jean for your reply.
I just started coding/unity and I just know the basics of it.
I'll take a look at Vectorisity and try to google more. If I won't find a solution or no one will be able to help me ,  I'll bump it.

Thank you so much.


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Changing script to playmaker States.
« Reply #3 on: March 04, 2015, 03:39:52 AM »
hi,

 yeah, please bump if you are getting nowhere.

 Bye,

 Jean

bartas

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Changing script to playmaker States.
« Reply #4 on: March 18, 2015, 01:32:04 PM »
Hello,

I'm bumping this topic , cuz I actually didn't manage to do it by myself.

Actually I'm looking forward to similar script that will set the  velocity after connecting with trigger, just like this script above is doing by tapping mouse1 button at the start.

thank you!