Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: coxy17 on May 19, 2014, 03:34:44 AM

Title: Translate Per Second [SOLVED]
Post by: coxy17 on May 19, 2014, 03:34:44 AM
Hi,

Im using translate to make the player move in (Self) space (Z Axis) and im using the FixedUpdate, PerSecond and Every Frame enabled.

However, i wanted the translation to happen slower. I have come to realise that i cant change this in Playmaker as there is no option to under Translate Action.

Other topics have advised to use TransformDirection. I have know idea how to use this. Is this something i should use to achieve what im after? https://hutonggames.fogbugz.com/default.asp?W477 (https://hutonggames.fogbugz.com/default.asp?W477)

Thanks

Nick
Title: Re: Translate Per Second
Post by: jeanfabre on May 20, 2014, 01:46:27 PM
Hi,

 Slower only means you should lower the z value, instead of 10 put 5 and it will go twice as slow.

 
 Bye,

 Jean
Title: Re: Translate Per Second
Post by: coxy17 on May 21, 2014, 04:30:49 AM
Hi Jean,

Sorry just realised i wasn't specific enough in my first post. I understand that reducing the number will make it slower. However, i want the player to reach an X distance over time. e.g. 10 (equivalent in World space). its a 3D game btw

Im using Translate to make my character walk. I think Vector3.Lerp is along the lines of what im after but dont think i can achieve the same type of movement as the Translate action does with this, as Lerp starts of with an ease and finishes with an ease.

Behavior:
If the player is still holding forward it will keep going another 10 etc. If the player lets go of forward it will finish the last translation to the last X distance.

e.g. player presses key and player moves 10 over 3 sec. IF the player lets go before 3 sec is up then the player finishes its movement before stopping.

Ive drawn a diagram to visually show what im after

hope it helps :)

Nick
Title: Re: Translate Per Second
Post by: jeanfabre on May 21, 2014, 06:43:11 AM
Hi,

 ok, for this you'll need to use a tweening engine, where you can define an absolute target to reach within a define duration.

 Have you tried this?

Else, you can compute yourselve the actual values to inject in this translate action:

the equation to get the translation amount per seconds when you know the total distance and duration is a simple mathematical cross product:


total translation -> total duration
delta translation -> 1 second

delta translation = (1*total translation)/total duration

Does that make sense?

Bye,

 Jean



Title: Re: Translate Per Second
Post by: coxy17 on May 21, 2014, 08:27:39 AM
Hi, it sort of makes sense. Ive not looked into tweening yet.

I'll take a look at both of your suggestions.

I'm using physics to control my character so would tweening affect this? I have my player walking up walls etc

Thanks again

Nick
Title: Re: Translate Per Second
Post by: Lane on May 21, 2014, 08:42:52 AM
It's best not to mix physics and forced translation. You can pass doing it for some things but since the position updates will change the position of the object its going to fight the physics inputs the entire time and usually gives unexpected results.

Possibly you might look into something along the lines of using a tween on a vector then injecting that into an Add Force action. Basically the idea being do the math on the vectors you want in the background but push them through the physics actions so the two systems aren't fighting.
Title: Re: Translate Per Second
Post by: coxy17 on May 21, 2014, 10:33:40 AM
Hi

Lane
Im sort of understand what you mean, but im new to this area so i would need to research in order to get a working example.

Jean
Quote
total translation -> total duration
delta translation -> 1 second

delta translation = (1*total translation)/total duration

Does that make sense?

How can i achieve this in playmaker? what states would i need. So i can experiment? or would i have to create my own script?

thanks

Nick
Title: Re: Translate Per Second
Post by: coxy17 on May 22, 2014, 10:06:05 AM
Hi,

Ive tried looking into Delta Time and i am struggling with how to construct it in playmaker

Would i need the following? would i need to store DeltaTime and put into Translate action?
Title: Re: Translate Per Second
Post by: jeanfabre on May 23, 2014, 12:52:53 AM
Hi,

 you don't need the delta since the check box "per seconds" is doing that for you in the background.

 Allow me few days ( bump sometime next week) and I'll do a micro sample shoing this.

Don't overthink this tho, it's a division of the total distance by the duration, and you inject that into the translate value, that's all there is to it really.

Bye,

 Jean
Title: Re: Translate Per Second
Post by: coxy17 on May 23, 2014, 03:11:38 AM
Hi Jean,

Oh ok. I would really appreciate you offering to create a micro sample. Really getting into this and i work better with demos.

I will bump next week

Thankyou

Nick
Title: Re: Translate Per Second
Post by: coxy17 on May 28, 2014, 03:05:28 AM
bump
Title: Re: Translate Per Second
Post by: jeanfabre on May 29, 2014, 01:45:30 AM
Hi,

 ok, here we go, download this micro sample (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/PlayMaker/Ecosystem/Custom%20Samples/Transform/TranslateUsingTimeAndDistance.unitypackage)

It's simple enough to understand what's going on. We compute first the translation value, and then we translate using that value and exit the state with a timer so that we translate during the right amount of time.

 I still encourage you to use proper tweening engines as they will give you more flexibity.

Bye,

 Jean


Title: Re: Translate Per Second
Post by: coxy17 on May 29, 2014, 02:37:26 AM
Hi, thanks I'll take a look :)

If I use tweening engines then won't this conflict with physics? I have gravity switches etc.

Nick
Title: Re: Translate Per Second
Post by: jeanfabre on May 29, 2014, 02:42:31 AM
Hi,

 Translate will conflict just as much as itween would.

 For physics, you should use "forces" to move objects around.

 Bye,

 Jean
Title: Re: Translate Per Second
Post by: coxy17 on May 29, 2014, 09:36:33 AM
Hi Jean,

The example is great and i understand now what you have done

However, i noticed that the distance in player has moved is always slightly off a round number and is never the same number. e.g. moving from 0 > 10 on Z sometimes finishes on 10.0301 or 10.00004 etc. Why is this?

Is this due to the 'Wait' action not kicking in at the same time during runtime?

i need this exact to the round number e.g. 10 as when the player moves again it starts to increase the value further away from the values im after.

what im after e.g.
0 > 10 > 20

what im getting
0 > 10.0201 > 20.1200

Thanks

Nick
Title: Re: Translate Per Second
Post by: jeanfabre on May 30, 2014, 08:08:14 AM
Hi,

 Indeed, well spotted. Typically, this is why I recommend using tweening engines for this, because they enforce reaching the end value perfectly ( at least that's my experience of it, maybe not all tweening engines do so).

 Here, because we are using timed event, the last frame is never likely to properly be of the right amount, this coupled with a potential small imperfection in timing within PlayMaker internal management of time ( I mentionned it on the beta list).

 Typically, and I didn't for this example, cause that's nto the point, I would enforce upon exiting the translate routine to position the gameobject where it's now suppoed to be perfectly.

also, bear in mind that the offset is like really small, so I don't think it really affects the game play isn't it? or are you looking for absolute precision here?

bye,

Jean
Title: Re: Translate Per Second
Post by: coxy17 on May 30, 2014, 09:15:52 AM
Hi Jean,

I understand what you are saying. i am after an absolute positioning in my case.

Reason is that i have a grid based game and from the players birds eye view they land on a block which is precisely centre. I have already thought about the fact why do i need to be e.g. on 10 and if its on 10.1 why should i be bothered.

One scenario is the player keeps going forward without making any turns and then will end up being very offset.
e.g. 0 > 10.04 > 20.1 > 30.12 > 40.2 ........end up being 130.5 or something

Couldnt i set a trigger up on each square in my grid and have the trigger drag the player back to the centre when idle? or player decides to stop. Not a great idea i know lol
Title: Re: Translate Per Second
Post by: jeanfabre on May 30, 2014, 09:31:50 AM
Hi,

 not a problem. As I said, simply add a repositioning action when you leave the translate state. And if you are using a grid based, I am sitll unsure why you don't want to use an iTween call?

Also, you may want to look at some grid systems on the asset store, it seems you could speed up your process by using a framework.

Bye,

 Jean
Title: Re: Translate Per Second
Post by: coxy17 on June 03, 2014, 08:42:02 AM
Hi Jean,

Ive taken a look and ive just kept your translate action as it works for me :)

Ive added a Trigger which re-positions the player upon stopping. Like you said the numbers only minute and when i update the position you cant tell the player had moved. Also collisions work fine with this method. Not painful iTween setup, as it would require me to study more lol

Just out of curiosity before i put this to solved, if i have loads of Triggers will this cause performance issues?

Nick
Title: Re: Translate Per Second
Post by: jeanfabre on June 03, 2014, 09:27:48 AM
Hi,

 lots of triggers are fine, as long as yo uonly use enter and exit events, not "stay", which is a bit of a problem performance wise if abused.

Bye,

 Jean
Title: Re: Translate Per Second
Post by: coxy17 on June 03, 2014, 09:44:26 AM
thanks, that's good news i only need the enter/exit