playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - szomaza

Pages: [1] 2 3 ... 14
1
General Discussion / Re: Doodle Jump like smooth movement
« on: December 02, 2018, 03:12:22 AM »
Thanks Thore!
I totally forgot about your initial suggestions from a page before.
I was trying to come up with a solution myself, but now your suggestions make much more sense to me reading them again.
I'll continue and wrap my head around them....

Thanks a bunch!

edit: I tried your AxisToVelocity2D and it works really nicely.
Thank you very much!

2
General Discussion / Re: Doodle Jump like smooth movement
« on: December 01, 2018, 09:39:46 AM »
I made some progress.
My camera is now Cinemachine which seems to be quite smooth and I can handle various camera behaviors I will need later.

Also I changed now from moving the player with RigidBody2dMovePosition (which was quite jittery) to SetVelocity2D as this guy explains here:
https://youtu.be/fHN-26GEVhA?t=845
That is smooth, just jumping up and down, but then he explains how to do about the same for the horizontal movement, here:
https://youtu.be/fHN-26GEVhA?t=1331
which part I am unable to replicate in Playmaker.

My problem is that I am not not sure what I should do differently to get his result.
Is this even possible in Playmaker?
Please check the attached image and tell me if this is even possible.

It seems so simple, but what is the problem?

There is one FSM which is doing the up and down jumping with SetVelocity2D once every time a platform 2D collider is entered.
I guess the problem is with the EveryFrame part of this horizontal movement FSM actions, they get the velocity of the object add the horizontal movement and then set the velocity every frame, so that is why the character flies away when this FSM is active.
What is he doing differently in his script? He does not have everyframe there but fixedupdate.

Please shed some light!

3
Thanks for the actions!

I noticed that the "Get Multilevel GameObject" is a bit buggy.
- With 0 it gets the owner as it should,
- With -1 it does not do anything, (something buggy here and then all the rest are offset)
- with -2 it gets the 1st child,
- with -3 it gets the 1st child of the 1st child,
- ...

Br,
szomaza


Code: [Select]
// License: Attribution 4.0 International (CC BY 4.0)
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/
// Author : Deek

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.GameObject)]
[HelpUrl("http://hutonggames.com/playmakerforum/index.php?topic=15458.0")]
[Tooltip("Get the Game Object and name of a higher parent or lower child specified by an index.")]
public class GetMultilevelGameObject : FsmStateAction
{
[RequiredField]
[Tooltip("The GameObject to start from.")]
public FsmOwnerDefault startingFrom;

[Tooltip("How many 'Directories' to go up or down. For example '2' would be the grandparent of the GameObject this FSM is attached to, '3' the parent of that one ... and so on. 0 returns the Owner. Anything below 0 goes in the other direction (-2 = first Child of the first Child). You can also set a very high number to definitely get the root.")]
public FsmInt index;

[UIHint(UIHint.Variable)]
[Tooltip("The final GameObject it reached.")]
public FsmGameObject storeResult;

[Tooltip("The Name of the final GameObject it reached.")]
public FsmString storeResultName;

[Tooltip("Follow the path it takes (throws Debug.Log's for every GameObject it passes). If there are several Log entries with the same GameObject, it means that the given index is higher than the GameObject has parents or lower than it has children.")]
public FsmBool debug;

public override void Reset()
{
startingFrom = null;
index = 1;
storeResult = null;
storeResultName = null;
debug = false;
}

public override void OnEnter()
{
var go = Fsm.GetOwnerDefaultTarget(startingFrom);
if(go != null)
{
//Get Owner
if(index.Value == 0)
{
storeResult.Value = Owner;
storeResultName = storeResult.Value.name;
if(debug.Value == true)
{
Debug.Log("GetMultilevelGameObject - Owner: " + Owner);
}

}

//Get ascending parent
if(index.Value > 0)
{
for(int i = 1; i < index.Value; ++i)
{

go = go.transform.parent == null ? go : go.transform.parent.gameObject;

if(debug.Value == true)
{
var j = i + 1;
Debug.Log("GetMultilevelGameObject - Parent " + j.ToString() + ": " + go.transform.gameObject.name);
}

storeResult.Value = go;
storeResultName = storeResult.Value.name;
}
}

//Get descending Child
if(index.Value < 0)
{
for(int i = -1; i > index.Value; i--)
{
go = go.transform.GetChild(0) == null ? go.transform.gameObject : go.transform.GetChild(0).gameObject;

if(debug.Value == true)
{
//Invert and add 1 to current Index
var j = (i * (-1)) + 1;
Debug.Log("GetMultilevelGameObject - Child " + j.ToString() + ": " + go.transform.gameObject.name);
}

storeResult.Value = go;
storeResultName = storeResult.Value.name;
}
}

}
//If startingFrom is Null
else
{
storeResult.Value = null;
storeResultName = "None";
if(debug.Value == true)
Debug.Log("GetMultilevelGameObject - NullReferenceException: 'Start From' is null");
}
Finish();
}
}
}

4
General Discussion / Re: Doodle Jump like smooth movement
« on: October 27, 2018, 12:40:56 AM »
Thank you very much!

Now this seems to be an equivalently good solution to the problem but in such cases:

How do I know which one is better?
Uses less resources?
Or should something else be considered to decide which one to use?

1. changing the layer of the object to a non-colliding layer,
or
2. using IgnoreLayerCollision2D to achieve the same.

5
Yes, I could get the world position of the object, parent it, and then set the world position back but wouldn't that cause it to flicker for a moment, as the parenting moves it away, and then the set world position moves it back?

Or do I read it here correctly that every action in a state is run in the same frame?
So there won't be no flickering?
https://hutonggames.fogbugz.com/default.asp?W174

What I am trying to do is random generating the level for a platformer:
- place a platform,
- spawn some elements: enemies, helpers, coins, etc. onto some child points (I use SetParent with ResetLocalPosition TRUE) of the platform,
- then when the platform is out of the camera view, parent it back to the platform pool object to be reused later,
- BUT some elements of the platform which were spawned to be parents of the platform's spawn point, have to stay around for longer, so this is when I tried to parent the element, to a temporary parent (to remove it from the platform before moving that away) and was hoping it would stay in the same position, but instead it jumps to another location.
(Thore is probably right with the local space guess.)

I'll try and return with the result.....

edit: it works nicely, the object does not flicker at all:
- GetPosition in World space,
- Parent away from the platform to something else,
- SetPosition back to same World space position.
all in the same state.

- Move the platform away, (this is actually in another FSM)

Thanks,
szomaza

6
General Discussion / Re: Doodle Jump like smooth movement
« on: October 24, 2018, 10:08:31 AM »
LOL, sorry it works perfectly...  ,but for 3D physics.

I just realised the name of it is:
PhysicsIgnoreLayerCollision
and not
Physics2DIgnoreLayerCollision
:-)

I am making a 2D platformer and I did check the collision matrix to make sure, but only the 2D matrix.

Anyway I am using the SetLayer action to set the Player to a non-colliding layer for the time it is being teleported and that seems to be working nicely.

7
I have used the SetParent action a lot but have a problem now that I can't explain.
The SetTransformParent behaves exactly the same, so I guess it is not a bug, but I don't know how to solve it or the reason this is happening.

I have an empty test object that I parent back and forth (with 1 sec delays) between a few empty test objects, around and around, one after the other, which are in different positions.

ResetLocalPosition and Rotation is FALSE in the SetParent actions, and first everything works as expected: the object stays in place just moves in the Hierarchy to the other parents, one after the other.
Problem starts, when I grab the Object being parented and move it around while it is being parented: it starts jumping around as it goes from one parent to the other.
It does move nicely along with the cursor all the time, but jumps to another spot when it gets parented to a new parent.
While it is parented to the original parent it jumps to the cursor and keeps on nicely moving with it.

My problem is that I was not expecting this jumping of the moving object when it is parented to another parent.
Why is this?
How can I get a moving object to keep moving on steadily, while it's parent is updated.

Thanks for any enlightenment,
szomaza

8
General Discussion / Re: Doodle Jump like smooth movement
« on: October 20, 2018, 10:17:04 AM »
Hmmm, I still can't get it to do anything. 
I simply set it to ignore player and platform collisions to try it but still he keeps bouncing on the platform.
What should I try to find the/my problem?

9
The Vector2Interpolate does not fire the FinishEvent in case the InterpolationType is set to EaseInOut.
Firing the FinishEvent works in case the InterpolationType is set to Linear.

I guess this part has the bug:
storeResult.Value = Vector2.Lerp(fromVector.Value, toVector.Value, weight);
         
         if (weight > 1)
         {
            if (finishEvent != null)
               Fsm.Event(finishEvent);

            Finish();
         }

It says
if (weight > 1)

But here:
https://docs.unity3d.com/ScriptReference/Vector2.Lerp.html
it says that weight can only be 0-1 so

if (weight > 1)
should be, right?
if (weight >= 1)

.... I felt brave as I was writing this, tried it out and LOL it works with that modification.

br,
szomaza

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Vector2)]
[Tooltip("Interpolates between 2 Vector2 values over a specified Time.")]
public class Vector2Interpolate : FsmStateAction
{
[Tooltip("The interpolation type")]
public InterpolationType mode;

[RequiredField]
[Tooltip("The vector to interpolate from")]
public FsmVector2 fromVector;

[RequiredField]
[Tooltip("The vector to interpolate to")]
public FsmVector2 toVector;

[RequiredField]
[Tooltip("the interpolate time")]
public FsmFloat time;

[RequiredField]
[UIHint(UIHint.Variable)]
[Tooltip("the interpolated result")]
public FsmVector2 storeResult;

[Tooltip("This event is fired when the interpolation is done.")]
public FsmEvent finishEvent;

[Tooltip("Ignore TimeScale")]
public bool realTime;

private float startTime;
private float currentTime;

public override void Reset()
{
mode = InterpolationType.Linear;
fromVector = new FsmVector2 { UseVariable = true };
toVector = new FsmVector2 { UseVariable = true };
time = 1.0f;
storeResult = null;
finishEvent = null;
realTime = false;
}

public override void OnEnter()
{
startTime = FsmTime.RealtimeSinceStartup;
currentTime = 0f;

if (storeResult == null)
Finish();
else
storeResult.Value = fromVector.Value;
}

public override void OnUpdate()
{
// update time

if (realTime)
{
currentTime = FsmTime.RealtimeSinceStartup - startTime;
}
else
{
currentTime += Time.deltaTime;
}

float weight = currentTime/time.Value;

switch (mode) {

case InterpolationType.Linear:
break;

case InterpolationType.EaseInOut:
weight = Mathf.SmoothStep(0, 1, weight);
break;
}

storeResult.Value = Vector2.Lerp(fromVector.Value, toVector.Value, weight);

if (weight > 1)
{
if (finishEvent != null)
Fsm.Event(finishEvent);

Finish();
}

}
}
}

10
General Discussion / Re: Doodle Jump like smooth movement
« on: October 15, 2018, 10:10:08 AM »
Hi djaydino,

I just tried your above 2 ideas and they worked perfectly to solved my problem:

1. using the SetLayer action to set it for the player to a non-colliding layer for the time it is teleported to the other side.
2. EnableCollider2D also works the same way.

Both needed a 0.1 sec. wait before turning them back on after the teleport. One frame wait was not enough and it also occasionally glitched (teleporting the player back and forth) with only 2 frame wait.

I also tried your action but it does not seem to work. I am not sure what is the problem. It does not seem to be doing anything.
I set it to ignore the collision of my player layer and the dynamic blocks but still they collide.

11
General Discussion / Re: Doodle Jump like smooth movement
« on: October 14, 2018, 04:33:49 AM »
Thank you djaydino, great ideas!
The set layer for the duration of the teleport sounds straightforward and the easiest to try for me right now but I'll try the set position also.
I have been moving the kinematic rigidbody2d character with set position before but then got afraid of that after reading here:

https://docs.unity3d.com/Manual/class-Rigidbody2D.html

"Kinematic Rigidbody 2D is designed to be repositioned explicitly via Rigidbody2D.MovePosition or Rigidbody2D.MoveRotation."

After this I switched to Rigidbody2D.MovePosition hoping that this way it will detect the platform Enter2DCollider more reliably and might never fall through a platform.
Which would be a disaster in such a game.

12
General Discussion / Re: Doodle Jump like smooth movement
« on: October 14, 2018, 12:58:57 AM »
Hi Thore,

Thank you very much!
Great ideas and lots of stuff to take in. I'll be occupied with those for a while.

I do have one question right away about using a rigidbody2d as the player and moving that around. I have that setup now (as the latest attempt to make it work) and the problem with it is when "teleporting" from one screen side to the other.

(In Doodle Jump the character can move out on one side of the screen and enter on the other side: teleporting from one edge of the screen to the other.)

The problem with this is that the RigidBody2dMovePosition
https://docs.unity3d.com/ScriptReference/Rigidbody2D.MovePosition.html
as it rapidly moves the character from one side to the other, it affects dynamic objects in the center of the screen.
If there is a tower made out of dynamic blocks, it will just instantly push any block hit, all the way to .... Siberia (...I guess, as they just disappear when the character is teleported across them)

This is the reason, I am thinking to go back to not using a rigidbody2d as the player, but fake everything: have the player character be just a regular object moved by it's transform, use raycasts to detect platforms.
Of course then I'll have problems with player interacting with dynamic physics objects: pushing them around.

I would appreciate any encouragement, insight on why to go one way and stick with that setup for such player character.

Thanks,
szomaza

13
General Discussion / Re: Doodle Jump like smooth movement
« on: October 13, 2018, 05:37:57 AM »
Also what about collision detection with platforms the player character jumps on?
It can NEVER happen that the character falls through a platform.

Is it good to rely on collision enter 2d events to detect falling on platforms or can/should it be more reliably faked?

I read something about 2d raycasts.
How does that work?
Do you have to cast a ray down from the character, then store that position and check until the character goes under it and then jump again?

Thanks,
szomaza


14
General Discussion / Doodle Jump like smooth movement
« on: October 13, 2018, 05:08:01 AM »
I am attempting to make something similar to Doodle Jump but the player character and camera movement is quite jittery.
I unfortunately have no idea how this should be done the best way.
Please share any thought or own experience I should try.

I have tried many different camera follow actions but none worked smoothly as in Doodle Jump.

The best so far I could do is move the player (kinematic rigidbody) with RigidBody2dMovePosition.
Setting it's position to an animated float curve value, simulating the jump height change.
And the camera is following this object.
Please see attached image for details of the current setup.

Thank you in advance for any ideas on how such a thing should be done to have it move smoothly.

br,
szomaza

15
Hi,

Just tried FighterCameraAdvance2d and in
2018.2.7f1
Playmaker: 1.9.0.p4

it says:

Code: [Select]
NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMaker.Actions.FighterCameraAdvance2d.CalculateCameraPosAndSize () (at Assets/PlayMaker Custom Actions/Camera/FighterCameraAdvance2d.cs:271)
HutongGames.PlayMaker.Actions.FighterCameraAdvance2d.OnLateUpdate () (at Assets/PlayMaker Custom Actions/Camera/FighterCameraAdvance2d.cs:154)
HutongGames.PlayMaker.FsmState.OnLateUpdate () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:277)
HutongGames.PlayMaker.Fsm.LateUpdateState (HutongGames.PlayMaker.FsmState state) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2789)
HutongGames.PlayMaker.Fsm.LateUpdate () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2094)
PlayMakerLateUpdate.LateUpdate () (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerLateUpdate.cs:21)

edit:
the simpler: TargetsTrackingOrthoCamera action works.

Br,
szomaza

Pages: [1] 2 3 ... 14