playMaker

Author Topic: Smooth Translation in a Direction  (Read 517 times)

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Smooth Translation in a Direction
« on: August 07, 2018, 09:57:53 PM »
Hello,

My problem is probably super simple but I can't find the solution:

I have an old school dungeon crawler system: 1st Person square by square movement. (Grimrock, Dungeon Master, etc.)
The movement is simple: When you press a key, you move by 1 unit in that direction (every square is a 1 unit square, handy !)

I'm using a simple translate (no need for a character controller or full 360 physics movement here), but my translations are instant.

How could I have a slow and smooth translation from one square to another.
(like 1 second for example, with speed increase / decrease with a curve, between each square) ?

Thanks a lot ! I'm stupidly blocking on something that looks easy...

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3523
    • View Profile
    • jinxtergames
Re: Smooth Translation in a Direction
« Reply #1 on: August 08, 2018, 12:02:59 AM »
hi.
Get the current position, then use a operator to add a value for the new position and store in another variable (call it 'new position' for example)

Then for now you could use a float/vector2/vector3 interpolate action (There will be native tween actions with more options included in one of the next PlayMaker updates) and set the mode to ease in out and place the current position and the new position in it.
You can set the time to your needs.
Also set an event for when the action is Finished.
Store in a variable (call it 'Moving' for example)

Then use a 'set position' and turn on 'Every Frame' and place the 'Moving' variable.

In the next state do another 'set position' with 'Evety Frame' disabled and place the  'new position' variable.
This is just to be sure that the final position is correct.

miguelfanclub

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: Smooth Translation in a Direction
« Reply #2 on: August 08, 2018, 01:37:33 AM »
Use the tween actions for that. You have durations and curves.

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #3 on: August 09, 2018, 09:11:53 PM »
Hi guys !

Thanks for your feedback :)

I don't have de Tween options, even installing iTween ?
Do I need to reinstall Playmaker after ?

Anyway, I tried djaydino's method, and it works... almost ! :D
It move, with an ease and all...

But it moves in world position. In Local my Z is always the front of the player but it always goes in the World Z... even if I choose self for any of the actions (Set Position and Get Position... kinda weird)

Thanks already !

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3523
    • View Profile
    • jinxtergames
Re: Smooth Translation in a Direction
« Reply #4 on: August 09, 2018, 09:25:43 PM »
Hi.
Do you have 'Get Position' and 'Set Position' both set to 'space : self'

Its best not to use iTween as it is outdated and slow.
the new native tween action are coming soon :)

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #5 on: August 09, 2018, 09:47:32 PM »
Yes for the Get and the Set, I join a screenshot of the action stack if you want to check, thanks for your time !

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #6 on: August 10, 2018, 05:22:43 PM »
(I tried with a Vector3 but the result is far worst :D haha)

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #7 on: August 13, 2018, 09:52:22 PM »
Hello, me again :D

I tried with a Translate, apparently it keeps the Self/Local coordinates, but don't behave correctly (I can't have it move the right amount of unit in the right amount of time)

So it's the Set Position which can't move it in the Local coordinates even if Self is checked... Is this normal ?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3523
    • View Profile
    • jinxtergames
Re: Smooth Translation in a Direction
« Reply #8 on: August 15, 2018, 12:44:24 AM »
Hi.
I can see an issue in your image.

You are using 'float add' to the 'new_position_z' variable. this variable will always be 0 to start unless you feed it the current position.

instead you need to use a 'Float operator' and place the 'current_position_z' in float 1, then set '1' in float 2.
Set Operation to 'Add'
and place 'new_position_z' in "Store Result"

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #9 on: August 15, 2018, 08:45:35 PM »
Hi djaydino !

Thank you for your help !

Problem is that it still does the exact same thing than my actions:
It works but move my player in the world space (which seems logical, saying like that), but not regarding it's local orientation.

So no matter my player orientation, he will always translate in the positive Z axis of the world space, not its local Z axis...

While waiting for help, I tried another brand new system from scratch, with translations.

It works BUT...

The precision is not fully accurate (I always arrive with positions like: 1,0XXX instead of 1) and of course the lack of precision is bigger and bigger the more I move...

So I tried what you said: Getting the position before then adding 1 in a Set position at the end, to correct the precision: And so same result as before... the Set Position adds 1 in the World Space, no matter my Local Rotation.

I have the feeling than Get and Set Position in Self Space is not working (or still working as World), OR I did not understand how to use them.  :-\

I hope being clear with my long explanation,

Thank you for your time :)

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #10 on: August 15, 2018, 09:00:45 PM »
If you want to check, here is the new system in screenshot.

Btw: You can notice another problem: When I translate, the value I need to add must by 4 times bigger than what I want (that's why I put 4 in New_Z)

I cannot understand why ?

Same for my angles: if I want a 90 degrees rotation, I need to add 360 in a float...

But well... each problem at a time  ;D

miguelfanclub

  • Full Member
  • ***
  • Posts: 108
    • View Profile
Re: Smooth Translation in a Direction
« Reply #11 on: August 16, 2018, 06:39:55 AM »
Use itween actions.
It has one action to do exactly the same you want.

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #12 on: August 16, 2018, 09:37:35 AM »
I don't have the Tweens action in my Playmaker, and apparently it's currently deprecated anyway :-/

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 3523
    • View Profile
    • jinxtergames
Re: Smooth Translation in a Direction
« Reply #13 on: August 16, 2018, 10:39:51 AM »
Hi.

Playmaker Native tween action are coming soon :)

But usually when i use interpolate actions i use a set position in the next state to be sure to have the correct position.

So in your case make a state after the interpolate  and use 'set position' with the "new_z" variable

the sizeof the new position depends on your field size/pixels per unit etc you might want to resize things. also scaled items are best set in a parent with a scale of 1

Ulrick

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Smooth Translation in a Direction
« Reply #14 on: August 16, 2018, 04:55:45 PM »
Hello !

Yup I see for the final Set Position and your solution for the final precision works, thank you !

But the Local / World problem is still the same.
I join a screenshot if my explanation were not clear with the FSMs:

I want to go in the Local Z direction when I press Up / W (in green)
and it goes in the World Z direction, even with "Self" selected in the Get / Set positions (in red)

It seems super simple tho...