Flutter Flame game - animation speed (update duration) - flutter

for those who are familiar with using Flame in Flutter for game development, I'm wondering if you can just advise me whether I'm on the right track, or not - because I'm not sure if what I'm seeing in my testing is what I expected. I started out with Flame because I thought it seemed like a relatively simple way to make the basic game that I'm aiming to make.
I'm making a basic game where there are four boundaries defined on each edge of the screen, and a ball will bounce around the four boundaries. The boundaries are defined as widgets (because I want to control the properties of each - sometimes they'll be "electrified", meaning the ball shouldn't collide with them). And the ball is a widget as well, of course. I've got some basic code done where I can drag a line from the ball to indicate the direction that I want to start bouncing, and then the ball will bounce around the boundaries (just using basic angle of incidence = angle of reflection to determine the direction of movement).
The code to do the movement is in the "update" method of the ball widget - however, what I'm finding is that the time between updates is somewhere around 200-300 milliseconds, so if I want to show the ball moving at any kind of pace, it has to jump a good number of pixels at each "update" tick - and thus the movement looks "jerky".
Am I doing this the right way? Is there a different (better) approach that will make the movement appear smoother? Or, I'm wondering whether the duration of the "update" ticks is a result of running the code via debug in an Android emulator? (I'm using Android Studio for the emulation, and Visual Studio Code to build the project). I know I don't have actual code here in the question, because essentially I don't have an issue with my code not running - I would just like to understand if that duration of "update" ticks is "normal", and if the resulting "jerky" animation is just to be expected - or do I need to look at a different approach? Thanks in advance!

You should preferably not be using widgets for moving game parts, you should be using Flame components. So you could have for example 4 SpriteComponents as the walls and then the ball as another SpriteComponent and then you can use the collision detection system to act upon when the ball touches one of the walls.
https://docs.flame-engine.org/main/collision_detection.html

Related

Why does using PhotonRigidbody2DView give 'elastic' movement?

I'm currently using photon pun 2 to learn simple 2d multiplayer.
Using PhotonRigidbody2DView is giving an 'elastic' movement to the player. The player goes forward a bit and then returns to the original position.
Here's the video:
https://youtu.be/HgFVsofVZcQ
Why does this happen and how do I solve this?
I tried using PhotonTransformView and PhotonTransformViewClassic but it is giving weird results. The players go inside each other and when one player collides the other, the other player starts jittering.
So I decided to use PhotonRigidbody2DView instead. Now the players don't go inside each other and the jittering is also not happening but the 'elastic' movement problem is happening.
This happens because the remote client uses the velocity of the rigidbody to reproduce the movement of the character is does not control. This makes it a bit independent from the lag but for arcade style movement (where direction changes are immediate), this doesn't work all that well.
Solutions to this depend on what you actually need. Networked objects combined with physics can be tricky to get right. For PUN 2, we didn't implement a solution to this case and assumed you'd tweak the PhotonRigidbody2DView as needed.
The Smooth Sync package in the Asset Store seems to do well and is a plugin to PUN 2.
Alternatively, the newer Photon SDK "Fusion" should do better and is state of the art as networking solution.

How to make an object bend in the opposite direction as it moves into Unity

I need to move a 3D object like in the "Run sausage" game.
https://www.youtube.com/watch?v=CQa5PUlSfwk
There, as the character runs forward, its body kind of bends backwards, in the direction opposite to the movement.
In particular I do a simulation of a tornado in Unity, but when I want to go forward to the upper part of the tornado moved back, and after 1 second reaches the lower part ("legs")
Any suggestions would help me. Thank you
The movement like in the Sausage Run game can be achieved easily by using animator controller specifically Blend Tree. Watch this tutorial is you are not already familiar with these
https://www.youtube.com/watch?v=E-zQw4GabKw

How can I implement input movement?

I am new to UE and trying to make very simple game to learn the engine.
This is how the game looks
I want the player to be able to move the cube(PlayerPawn) left and right only.
This is my script to move the pawn.
But when I go left or right it also rotates. How can I fix this? How can I implement input movement while the pawn simulates physics?
You're applying floating pawn movement on a non floating object? That just doesn't seem right does it?
If you want to use custom movement just setup a collision component (BoxComponent in your case maybe?) And apply forced with SetForce/AddImpulse or SetLinearVelocity.
Also might be worth your time looking into the Character blueprint clasd that comes with lot's of premade movement capabilities

SpriteKit snake - joints and physics

I'm working on my game - Snake for iOS.
My development has already passed this stage, however I think about doing some refinements to it. After several tries and errors I've totally ignored physics/movement and collision detection offered by SpriteKit and I keep using my own implementation. Perhaps with your help I may refactor this parts of the game.
My snake can turn in all possible directions (360 degree). There is no gravity. How would you set up your physic bodies if you would prefer to offset as much as a code to existing SpriteKit implementation?
There are two important parts I think.
First - joints. Snake is constructed from multiple physic bodies. All bodies simply follow one another - going through all the points that the head was some time ago. I assume the best joint for this is Pin joint? I used Pin joints with anchor point exactly between neighbouring bodies. But this setup caused the rest of the snake's body to change the physics of the head. It shouldn't be like that. I tried changing the weight to zero, putting linear and angular dumping to maximum. The result was never acceptable.
Second - controlling movement. The movement of the snake is constant. User by pressing left and right button starts gentle movement of the snake to the right or left. Do you think I should in the update method reset the snake's velocity each time to my constant value? Or should I play with forces impulses and torques? The turning only takes place when user keeps pressing the screen - it takes few seconds to reverse the snake (like "u-turn") - how about rotating it?
Any suggestion is appreciated. Best regards.

Dragging a Sprite (Cocos2D) while Chipmunk is simulating

I have a simple project built with Cocos2D and Chipmunk. So far it's just a Ball (body, shape & sprite) bouncing on the Ground (a static line segment at the bottom of the screen).
I implemented the ccTouchesBegan/Moved/Ended methods to drag the ball around.
I've tried both:
cpBodySlew(ballBody, touchPoint, 1.0/60.0f);
and
ballBody->p = cgPointMake(touchPoint.x,touchPoint.y);
and while the Ball does follow my dragging, it's still being affected by gravity and it tries to go down (which causes velocity problems and others).
Does anyone know of the preferred way to Drag an active Body while the physics simulation is going on?
Do I need somehow to stop the simulation and turn it back on afterwards?
Thanks!
Temporarily remove the body from the space.
If you want the object to have inertia when you release it, that's a different story. The cleanest way is to attach a fairly stiff spring between the ball and a temporary sensor body that moves under the control of your finger. When you let go with your finger, the ball will retain whatever kinematics it had while you were dragging it. Be sure not to remove the ball from the space in this case.
You aren't updating the velocity of the object when you aren't using cpBodySlew(). That is why it falls straight down.
A better way to do it is to use a force clamped pivot joint like the official demos do to implement mouse control. http://code.google.com/p/chipmunk-physics/source/browse/trunk/Demo/ChipmunkDemo.c#296