playMaker

Author Topic: 2D Physics questions about gravity[SOLVED]  (Read 4524 times)

Snowbird

  • Playmaker Newbie
  • *
  • Posts: 25
2D Physics questions about gravity[SOLVED]
« on: August 27, 2017, 02:19:06 PM »
So I am new to playmaker/unity and am following a few tutorials on youtube, but they seem a little wonky in 2017 unity.

Basically, after I add some basic movement to my player character, he then proceeds to fall extremely slowly, and he definitely doesn't accelerate to the ground like a normal rigid body would. This is in contrast to the videos I am watching where putting in a simple FSM has absolutely no effect on their characters relation to gravity.



It seems like every frame, it resets his Y velocity and acceleration, causing him to slowly inch towards the ground.

What is causing this and how can I remedy it?
« Last Edit: September 05, 2017, 03:09:12 AM by jeanfabre »

Deek

  • Full Member
  • ***
  • Posts: 133
Re: 2D Physics questions about gravity
« Reply #1 on: August 27, 2017, 04:30:32 PM »
That's because in your Set Velocity 2d Action you specify the 'Vector' variable with X:0 Y:0 and under that you only override the X value with xSpeed, leaving Y to be 0.
Updating that every frame resets the Y velocity to 0, thus creating a stuttering/slow downward movement of you GameObject since the RigidBody tries to simulate Gravity and pulls the GameObject down while this action constantly resets the resulting Y velocity.

So just click on the "=" symbol next to 'Vector' so that it says 'none' and you should be fine. If that doesn't work get the Y velocity with 'Get Velocity 2d' (also every frame; set 'Space' to "Self" if "World" didn't give the desired result) and insert that variable in the Y of 'Set Velocity 2d'.

Snowbird

  • Playmaker Newbie
  • *
  • Posts: 25
Re: 2D Physics questions about gravity
« Reply #2 on: August 28, 2017, 11:18:36 AM »
Alright, the first bit worked. My character started falling like a normal rigid body.....and then immediately clipped halfway through the edge collider on my terrain object.

Is it best to just set Unity's gravity and everything to "0" and work it out myself? I always seem to find weird bugs like this and I've only been playing with it for a month.

Deek

  • Full Member
  • ***
  • Posts: 133
Re: 2D Physics questions about gravity
« Reply #3 on: August 28, 2017, 12:52:31 PM »
You shouldn't need to work the physics out yourself, Rigidbody is your best bet to achieve fairly realistic and optimized movement compared to an own solution.
If your character moves through a collider but stops somewhere in it, then it's because there's something configured wrong.

The likeliest thing that should help is to set the Collision Detection from "Discrete" to "Continuous" in your rigidbody so that it updates the physics more often, which means that there is a slightly bigger performance impact (shouldn't be noticeable if you don't overdo it), but the collisions are more precise. Alternatively or additionally you can decrease the Fixed Timestep as described in the attached screenshot.

You should also read up on Rigidody's in the manual (https://docs.unity3d.com/Manual/class-Rigidbody2D.html) as it will make its options more clear and will definitely help you in the future to understand what does what.

Also try to use BoxColliders instead of EdgeColliders if possible because the bigger the collider, the less likely it is that object pass through.

Snowbird

  • Playmaker Newbie
  • *
  • Posts: 25
Re: 2D Physics questions about gravity
« Reply #4 on: August 29, 2017, 07:45:17 PM »
I tried some of those already but I hadn't touched the fixed timestamp. I lowered it from .02 to .005 and I don't have that problem anymore. Thanks for the help. I'll definitely start reading the manual