Increase speed but do not break kinematic objects behaviour

Hi!
I have a game mechanics prototype (video below) with this behaviour:

  • a ship can make a speed increase like a jet
  • a platform contais a set of kinematic objects (black rectangles) which may be hit by a bullet and fall (so that there is kinematic rigidbody2D on each rectangle except the lowest one)
  • in Unity the ship does not move - instead all the scene including the platform and kinematic objects move towards the ship by assigning rigidbody2D velocity which depends on whether jet mode is on or off:
if (jet) rb2d.velocity = jet_velocity;
else rb2d.velocity = no_jet_velocity;
  • this script is NOT attached to kinematic objects.

As you may see in video below near 0:11 swithcing to jet mode leads to strange kinematic objects behaviour
(strange for a player, for Unity it’s expected) - black rectangles slide to the right side of the screen.

What would you recommend to change so that black kinematic rectangles accelerate\decelerate in jet mode as player expects - move towards player with the ground?

Update:
if I attach the script to each kinematic objects:

rb2d settings:
7556392--934480--изображение_2021-10-08_111512.png

I’m really not following what you’re asking because mainly you keep talking about “Kinematic objects” but everything you’re showing isn’t Kinematic which makes me suspect something is getting lost in translation. How are the “black rectangles” Kinematic? I presume the “black rectangles” are the stacked structure in which case, those are collision responses I see and therefore are Dynamic body-types NOT Kinematic.

Ignoring that, why would you be moving the whole scene rather than the camera? Are you not making it really difficult for yourself here? If you’re trying to keep stacked structures (that are NOT Kinematic) stable then don’t go moving them through the world. You do know that physics works by calculating what velocity each should have for gravity and impulses due to collision? The solver “solves” this problem and keeps it working. You sound like you’re then stomping over their velocity with your own but then want it to keep working as usual. I guess I just don’t follow and maybe I’ve got the wrong idea on what you’re actually doing but it’s not that clear.

I will say though that the collision responses don’t look natural at all so are these Kinematic bodies and you’re modifying them? In which case, the collision responses are totally in your code.

Stability on these comes in combination of the solver iterations you set, the collision detection mode (discrete/continuous) and the forces being applied to them either via you directly or other colliders.

Thanks for your reply!
You are right, “black rectangles” are Dynamic, of course, as shown on screenshot of rb settings attached to 1st post.

And - as you may see near 0:06 in second video in 1st post, those “black rectangles” behave quite natural (fall down) even when my JET script modifies their velocity (faster, then slower).

why would you be moving the whole scene rather than the camera?

just because I’m playing around this Unity Learn tutoorial - https://learn.unity.com/tutorial/live-session-making-a-flappy-bird-style-game - which is based upon scrolling objects idea

Yes but it might be appropriate there as those are not dynamic bodies, they are “effectively” static geometry and only done to create a simple wrap around effect in a simple tutorial. It doesn’t state that this is how you do stuff moving forward and make it appropriate to extend that to more dynamic stuff.

I mean, take something like “Angry Birds”, it doesn’t move the whole world sideways as that would be crazy slow and unstable. Move the camera and the player and leave the world as is otherwise it’ll never be stable unless you really know what you’re doing.

In the end, it’s up to you so I can only give you my opinion based upon the little bit of info you’ve provided. Already you’re seeing problems so… :slight_smile:

Actually it looks like I have no problems after attaching the script (pretty surprisingly)
Will see, though…
Thanks!

I just don’t get why you would move many things when you should only move two things: the camera and player. If you somehow manage to get it all stable and predictable, it’s not an approach that scales well performance-wise.

That said, if this is a learning exercise then it’s all learning and all good.

Good luck!

that’s simple - now I have everything working in ‘a scroller world’, and migrating to new (‘moving ship’) mechanics takes time.
Before doing that it would be great to know Do I REALLY need to do that?
I tried to catch physics overhead in profiler - and I can’t see any significant influence of physics on performance (most of time used by VSync)