playMaker

Author Topic: How would you make this in Playmaker ? [SOLVED]  (Read 5890 times)

ryball

  • Playmaker Newbie
  • *
  • Posts: 4
How would you make this in Playmaker ? [SOLVED]
« on: January 07, 2013, 01:25:46 PM »
Code: [Select]
Var myspeed : float = 10;
var myrange : float = 10;

private var mydist : float;

function Update ()
{
     transform.Translate(vector3.forward * Time.deltaTime * myspeed);
     mydist += Time.deltaTime * myspeed;
     if(mydist >= myrange)
     {
        Destroy(gameObject);
     }
}
 

« Last Edit: January 09, 2013, 07:38:35 AM by ryball »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: How would you make this in Playmaker ?
« Reply #1 on: January 07, 2013, 03:09:59 PM »
Hey
transform.Translate() is the (EDIT)"translate" action. It transforms each frame by the forwards (local positive z dircetion, use transform direction if you need to use it locally) vector.
Time.deltaTime can be gotten with the "time Info" action.
myspeed is a predifined variable
In playmaker you need to use an additional variable to save the product of the term you want to use for the transform. If you use transform direction you'll calculate a new forward vector every frame so you can just use Vector3 multiply to multiply that vector with the floats from Time.deltaTime and the myspeed variable. This works like *= in scripting but saves you the need to convert the float into a vector3. Then use the vector as input in the translate action. Since Playmaker always works off a state from the top to bottom, the translate action must come after you've calculated the transform vector.
All of the actions should have an every frame option to simulate the Update function.

mydist += Time.deltaTime*myspeed  does the same as "float add" every frame.

if (mydist >= myrange) is a "float compare" which only sends events if mydist is bigger or equal myrange.
Then it needs to go to a new state with a destroy self action in it.

Did that help? Did you code that yourself?
« Last Edit: January 07, 2013, 04:18:11 PM by kiriri »
Best,
Sven

ryball

  • Playmaker Newbie
  • *
  • Posts: 4
Re: How would you make this in Playmaker ?
« Reply #2 on: January 07, 2013, 03:39:57 PM »
This helps thank you.

Well the code is not mine but i understand it :) i just had some trouble figuring out how to translate it to Playmaker.

I will try to get it to work with playmaker now :)



ryball

  • Playmaker Newbie
  • *
  • Posts: 4
Re: How would you make this in Playmaker ?
« Reply #3 on: January 07, 2013, 05:00:12 PM »
Looks like i have problem getting this to work in Playmaker :(

What im doing is :
Get Time Info -> Delta time -> Value : Time Every frame
Float Multiply -> Time multiply by myspeed Every frame
Vector3 Multiply -> tempvector3 multiply by time
Transform Direction -> Local Direction tempvector3 Store result in myDist Every Frame.

I dont get any value in the vetor3 , its stays at 0 0 0 ..

What im trying to do is to fire a projectile that will destroy itself after a given distance.



kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: How would you make this in Playmaker ?
« Reply #4 on: January 07, 2013, 05:15:53 PM »
Regarding what you want to do, it's probably easier by using getDistance and/or a wait action. Alternatively you could also get the position of the player and that of the missile and use the vector3 operator to calculate the distance or the square distance if you're watching out for performance.

As for your problem, it seems that your tempvector3 is not really temporary ;)
vector3 multiply means you save the result to the same vector3, so if you multiply the vector each frame with a very low number it will eventually just round it to 0. You can either use a set vector3 each frame before you use the vector3 again so it will always be reset, or you can use the vector3 operator, which lets you specify a different vriable to store the result in.
Best,
Sven

ryball

  • Playmaker Newbie
  • *
  • Posts: 4
Re: How would you make this in Playmaker ? [SOLVED]
« Reply #5 on: January 09, 2013, 07:38:16 AM »
Thank you for great information i was not thinking that vetor3.forward is the same as 0.0.1

But using this combination works great :
Float add  : myDist add mySpeed , every Frame.
Vector3 Multiply  : forward multiply mySpeed , every frame.
Float compare :  myDist , myRange and send event destroy object if distance is reached.
Translate: vector3 , forward.

Thanks gain :)