playMaker

Author Topic: Is there a prefab 2D controller that use the rigidbody?  (Read 1789 times)

K3rne7

  • Playmaker Newbie
  • *
  • Posts: 8
Is there a prefab 2D controller that use the rigidbody?
« on: July 21, 2020, 08:06:15 AM »
Hi, I'm trying to develop a 2D platformer and I wish I could implement the movement, but without using the character controller> getAxis, but I wish I could move my sprite through the 2D rigidbody. To prevent the game from lagging with the character controller.
In the ecosystem, I found for 3D, this action, "Rigidbody Translate Position Auto". This, when you work with 3D box collider it works perfectly, but if you have to work with a polygon collider, you cannot do it, there is an action in the playmaker or in the ecosystem, which performs the same functions as Rigidbody Translate Position Auto, but with elements that are purely 2D?
I tried the ones that are available with the 2D ridigbody, but they work in jerks, "impulses" I would say, because they are used to achieve a goal, instead I would like full control of the 2d sprite, just as happens with the intervention "Rigidbody Translate Position Auto ", but I wish I could do it with 2D elements. This is because, with the Translate position auto for 3D, the movements of the character are very fluid and that action is very simple to use.
I would also like to ask for a personal opinion, having little experience, for a movement along the X axis, is it better to use the addForce with the rigidbody? Because I tried, but the force is not constant, it becomes an impulse, so the movement to the right and left is unnatural, jerky, I created 2 states, in the first there are the getKeyDowns, in the second the addForce, for the right and left.
I thank you for your help and support.
« Last Edit: July 21, 2020, 08:16:39 AM by K3rne7 »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #1 on: July 21, 2020, 08:31:20 AM »
No idea what you mean by character controller. Usually, you just need get axis (raw) and set velocity or add force (every frame). See here for a tutorial.

https://hutonggames.com/playmakerforum/index.php?topic=22352.msg98057

K3rne7

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #2 on: July 21, 2020, 09:54:24 AM »
No idea what you mean by character controller. Usually, you just need get axis (raw) and set velocity or add force (every frame). See here for a tutorial.

https://hutonggames.com/playmakerforum/index.php?topic=22352.msg98057

Thanks a lot for your answer, yes, in fact with get axis I solve the problem in 5 seconds, I used it too, but I encountered a problem with trigger events and collisions.
Put simply, get axis, uses the inputs that are called by the input menager within the project settings. But if I write "Horizontal", in axis name, rightly my sprite, it moves using the translate position and the transform of the sprite, but in doing so the rigidbody conflicts with the latter creating problems in the physics of the game.
So I wanted to use the rigidbody to move my character and optimize the game, rather than resorting to the translate / transform of the get axis.

In fact in the ecosystem, for 3D games, there is an action called "rigidbody translate position auto", which allows you to control the game character through rigidbody, instead of GetAxisVector which does the same thing, but through the transformation of the object. I want to find the same thing, but for a 2D sprite.

Usually in games it is always better to move the character via ridigbody if the game has many physical interactions, because often the characterController creates a lot of problems, starting from stairs, collisions between objects etc.
« Last Edit: July 21, 2020, 09:58:42 AM by K3rne7 »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #3 on: July 21, 2020, 01:53:21 PM »
The axis or input method has nothing to do with movement, it just returns a value (-1 to 1) based on the input. You move via rigidbody by using addforce or set velocity. Just be sure that you use a consistent set of physics components and actions: for 2D, rigidbody2d, raycast2d, collider2d, trigger2d and so on.

K3rne7

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #4 on: July 21, 2020, 05:33:13 PM »
The axis or input method has nothing to do with movement, it just returns a value (-1 to 1) based on the input. You move via rigidbody by using addforce or set velocity. Just be sure that you use a consistent set of physics components and actions: for 2D, rigidbody2d, raycast2d, collider2d, trigger2d and so on.

So the playmaker's getAxis action doesn't use the transform or translate position, does it use the rigidbody? Why with set velocity do I indicate to move the rigidbody at that speed?

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #5 on: July 21, 2020, 06:12:59 PM »
Get means to read some variable, so you can use it for something. Then, you can Set it (e.g. multiply with force, velocity etc. which is all physics, hence rigidbody). Again, check some basic tutorials or the actions I mentioned.

K3rne7

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #6 on: July 21, 2020, 06:31:34 PM »
Get means to read some variable, so you can use it for something. Then, you can Set it (e.g. multiply with force, velocity etc. which is all physics, hence rigidbody). Again, check some basic tutorials or the actions I mentioned.

I understood, thank you very much, I had this doubt because the 2D animations lagged, but the problem was of the rigidbody, it had to be set to interpolated, and not to none, in doing so the animations no longer vibrate in contact with the sprite. Anyway, you made me think about something I did not understand Thore, in fact getAxis, acquires an input, then the input value is stored in a variable and I choose where to use this value, if with setVelocity, addForce etc., the important is that this input is only a float value, not a change of transform or tanslate position.

I wanted to thank you for your help, sorry for the doubts, but I had to be sure, thank you very much! For me the post is solved;)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: Is there a prefab 2D controller that use the rigidbody?
« Reply #7 on: July 22, 2020, 05:34:32 AM »
Hi.
I just want to mention that add constant force is quite cpu heavy.
so preferably you should use velocity for left right moving.

for jump you can do several things, you can use for example a force impulse or use velocity with some tween to manipulate.