unity – RigidBody2D not moving properly

Description

I’ve seen some Unity tutorials and I’m trying to apply good practices to modularize the code. However, I’m running into some issues while trying to use rigidBody2d.MovePosition().

I have two classes: Player (which defines rules and performs calculations) and PlayerController (uses computed data from Player to interact with Unity itself).

Player.cs

using UnityEngine;

public class Player
{
    public Vector2 MoveTowards(Vector2 currentPosition, Vector2 direction)
    {
        return currentPosition + direction * 2f;
    }
}

PlayerController.cs

using UnityEngine;

(RequireComponent(typeof(Rigidbody2D)))
(RequireComponent(typeof(Animator)))
public class PlayerController : MonoBehaviour
{

    public Player player;

    Rigidbody2D rb2d;
    Vector2 movementDirection = Vector2.zero;

    void Awake()
    {
        player = new Player();
        rb2d = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        movementDirection = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
    }

    void FixedUpdate()
    {
        rb2d.MovePosition(player.MoveTowards(rb2d.position, movementDirection) * Time.fixedDeltaTime);
    }
}

What happens visually is the player’s sprite moves (just a tiny bit) towards the given direction and goes back to (x: 0, y: 0) as soon as I release the movement key.

Player on Inspector:
Player on Inspector

What I tested

Inside FixedUpdate, it does not work when I use:

rb2d.MovePosition(player.MoveTowards(rb2d.position, movementDirection) * Time.fixedDeltaTime);

Inside FixedUpdate, it does not work when I use:

Vector2 controllerNewPosition = rb2d.position + movementDirection * 2f;
rb2d.MovePosition(controllerNewPosition * Time.fixedDeltaTime);

Inside FixedUpdate, it works when I use:

rb2d.MovePosition(rb2d.position + movementDirection * 2f * Time.fixedDeltaTime);

Questions

Maybe that is being caused by the operator + and not creating a new Vector2, instead mutating rb2d.position? While I’m not new to programming, I have no experience with C#, so I don’t know the specifics of the syntax yet.

How could I use player.MoveTowards in this case?

Feeling dumb. Right after publishing the question I realized the glaring mathematical priority issue. I’ve been debugging this for hours. I guess it happens to everyone.

windows – Moving existing local profile to an AD roaming profile

Looking into moving existing local profile (Windows 8.1) to an AD roaming profile (WS 2019). The goal is:

  1. One user has 2 machines at once. One is win8.1 (existing one), another is win10 (fresh). Upgrade/downgrade is possible.
  2. Now user has local admin account on a win8 machine, which should be converted saving all profile settings to an existing fresh AD user-right account.
  3. Existing browser settings for Google Chrome and IE should be preferrably transferred between too, as well as Desktop links/files and Documents folder.

What are the steps for doing this? Also network is 100MB/s, is that enough for a kinda small profile roaming to be smooth?
Also, I’ve seen a User-profile disks feature, what is the difference between UPD and roaming profile and will it fit the task better? Thanks

pascalscript – Are there any benefits in moving some of this code from InitializeWizard to InitializeSetup in Inno Setup?

This question is a spin off from this one:

Report installed .NET Framework version during install with Inno Setup

Here is my InitializeWizard:

(* InitializeWizard is called when the wizard is about to begin.
    This is where we add any custom pages into the installation process.
    The relevant XXX_CreatePage methods should be defined BEFORE this method. *)
procedure InitializeWizard();
begin
    dotNetNeeded := not IsDotNetInstalled(net462, 0);
    if (dotNetNeeded) then begin
        if (MsgBox(ExpandConstant('{cm:DotNet_NeedToDownload}'), 
                                            mbConfirmation, MB_OKCANCEL) = IDCANCEL) then begin
            //result := ExpandConstant('{cm:DotNet_InstallAborted}');
            Abort();
        end;
    end;

    bVcRedist64BitNeeded := false;
    if (IsWin64()) then
        bVcRedist64BitNeeded := IsVCRedist64BitNeeded();

    bVcRedist32BitNeeded := IsVCRedist32BitNeeded();

    DownloadPage := CreateDownloadPage(SetupMessage(msgWizardPreparing), SetupMessage(msgPreparingDesc), @OnDownloadProgress);

    { Support File Progress Monitoring via ListBox }
    { See: https://stackoverflow.com/a/64588818/2287576 }
    { Start }
    OldStatusLabelWndProc :=
        SetWindowLong(WizardForm.StatusLabel.Handle, GWL_WNDPROC,
            CreateCallback(@StatusLabelWndProc));
    OldFilenameLabelWndProc :=
        SetWindowLong(WizardForm.FilenameLabel.Handle, GWL_WNDPROC,
            CreateCallback(@FilenameLabelWndProc));

    WizardForm.ProgressGauge.Top := WizardForm.FilenameLabel.Top;

    ProgressListBox := TNewListBox.Create(WizardForm);
    ProgressListBox.Parent := WizardForm.ProgressGauge.Parent;
    ProgressListBox.Top :=
        WizardForm.ProgressGauge.Top + WizardForm.ProgressGauge.Height + ScaleY(8);
    ProgressListBox.Width := WizardForm.FilenameLabel.Width;
    ProgressListBox.Height :=
        ProgressListBox.Parent.ClientHeight - ProgressListBox.Top - ScaleY(16);
    ProgressListBox.Anchors := (akLeft, akTop, akRight, akBottom);
    OldProgressListBoxWndProc :=
        SetWindowLong(ProgressListBox.Handle, GWL_WNDPROC,
            CreateCallback(@ProgressListBoxWndProc));
    { Lame way to shrink width of labels to client width of the list box, }
    { so that particularly when the file paths in FilenameLabel are shortened }
    { to fit to the label, they actually fit even to the list box. }
    WizardForm.StatusLabel.Width := WizardForm.StatusLabel.Width - ScaleY(24);
    WizardForm.FilenameLabel.Width := WizardForm.FilenameLabel.Width - ScaleY(24);
    { End }

    AutoBackupPage_InitializeWizard(wpSelectTasks);
end;

Here is my InitializeSetup:

{ Called just before setup is about to start }
function InitializeSetup(): Boolean;
var
    WinVer: TWindowsVersion;
    WinVerPacked: Int64;
begin
    Result := True;

    ExtractTemporaryFile('{#Skin}');
    LoadVCLStyle(ExpandConstant('{tmp}{#Skin}'));

    { Are we performing an upgrade? }
    bIsUpgrading := IsUpgrading();

    { Check Windows Version }
    GetWindowsVersionEx(WinVer);
    WinVerPacked := PackVersionComponents(WinVer.Major, WinVer.Minor, WinVer.Build, 0);

    (* Windows must be Win 7 SP1 (6.1.7601), Win 8.1 (6.3.9200) or higher, eg: Win 10 (10.0.10240)
        See: http://www.jrsoftware.org/ishelp/index.php?topic=winvernotes
        Microsoft .Net Framework 4.6.2 will only work with these operating systems. *)
    if (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 1, 7601, 0)) < 0) or
            ((ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 2, 0, 0)) >= 0) and
            (ComparePackedVersion(WinVerPacked, PackVersionComponents(6, 3, 0, 0)) < 0)) then
    begin
        MsgBox(SetupMessage(msgWindowsVersionNotSupported), mbError, MB_OK);
        Result := False;
    end;
  { Log(Format('Windows Version: %x', (WindowsVersion))); }
end;

Are there any benefits in moving some of this code from InitializeWizard to InitializeSetup? And if so, why?

email – Interaction Gmail and Mail.app – Moving messages locally

I use the Mail.app to access my multiple email accounts on my MBP and store some of the messages locally so that it doesn’t end up stored forever online.

The thing is, I feel like moving a message from my Inbox to a local folder (i.e. “On my Mac”) works for all accounts except Gmail.
Whenever I move a message from my Inbox to a local folder (either by drag-and-drop or with a rule in Mail.app), I discovered that the email is still in Gmail. It just isn’t in the Inbox anymore, I have to go to “All Mail” to see it.

Is there a way to erase the message from the server as soon as it is stored locally? (or even with some delay like with deleted messages) Otherwise, it kind of defeats the purpose of all this…

I discovered that more than 1,000 emails are still stored online while I stored them all on my mac…

combinatorics – Is there a way to list all partitions of a set by moving one element at a time?

Given a set $S = {1, 2, ldots, n}$, imagine that you start from an initial partition $P^{(0)} = {P^{(0)}_1, P^{(0)}_2, ldots}$ of $S$, then you a create new one $P^{(1)}$ by moving only one element from some subset $P^{(0)}_i$ to some subset $P^{(0)}_j$, and so on. Is it possible to list all partitions of $S$ in this way, such that no partition repeats in the list?

It’s possible when $n=1,2,3$. I don’t know for $n=4$. Any help is appreciated!

mathematics – Predict future position of a moving body in Phaser arcade physics

I am looking for an equation for predicting the future position of a moving arcade physics body in Phaser 3. The body has drag applied and isDamping set to true. Phaser applies the drag using the following run on each update (showing x axis only but same applies to y).

//  Damping based deceleration
dragX = Math.pow(dragX, delta);

velocityX *= dragX;

Given the above, how would I write a kinetic equation to predict the future position?

I am currently using the method below, where I am iterating over frames to calculate the position accumulatively. But this is inefficient and inelegant so would prefer a solution which estimates the position without any looping.

public futurePosition(timeInSeconds: number): Phaser.Math.Vector2 {
  const DELTA = 1 / 60; // Assume we are running at 60fps
  const DRAG = 0.3; // Drag value
  const position = this.position.clone(); // Current position of body
  const velocity = this.body.velocity.clone(); // Current velocity

  // Inefficiently looping through frames
  for (let i = 0; i < timeInSeconds / (DELTA * 1000); i++) {
    velocity.x *= Math.pow(DRAG, DELTA);
    velocity.y *= Math.pow(DRAG, DELTA);
    position.x += velocity.x * DELTA;
    position.y += velocity.y * DELTA;
  }

  return position;
}

Any help appreciated. Thanks.

mathematics – Predict future position of a moving body in Phaser’s arcade physics

I am looking for an equation for predicting the future position of a moving arcade physics body in Phaser 3. The body has drag applied and isDamping set to true. Phaser applies the drag using the following run on each update (showing x axis only but same applies to y).

//  Damping based deceleration
dragX = Math.pow(dragX, delta);

velocityX *= dragX;

Given the above, how would I write a kinetic equation to predict the future position?

I am currently using the method below, where I am iterating over frames to calculate the position accumulatively. But this is inefficient and inelegant so would prefer a solution which estimates the position without any looping.

public futurePosition(timeInSeconds: number): Phaser.Math.Vector2 {
  const DELTA = 1 / 60; // Assume we are running at 60fps
  const DRAG = 0.3; // Drag value
  const position = this.position.clone(); // Current position of body
  const velocity = this.body.velocity.clone(); // Current velocity

  // Inefficiently looping through frames
  for (let i = 0; i < timeInSeconds / (DELTA * 1000); i++) {
    velocity.x *= Math.pow(DRAG, DELTA);
    velocity.y *= Math.pow(DRAG, DELTA);
    position.x += velocity.x * DELTA;
    position.y += velocity.y * DELTA;
  }

  return position;
}

Any help appreciated. Thanks.