Skip to main content
added 4 characters in body
Source Link
ChrisC
  • 116
  • 1
  • 10

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

The movement on the x-axis should be smooth, i.e. it shouldn't jump from one spot to the next, but rather move to a specifiedspecified x-coordinate slowly.

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

Basically, I am looking for a hypthetical method Vector2.MoveTowards that only takes an x-input.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

The movement on the x-axis should be smooth, i.e. it shouldn't jump from one spot to the next, but rather move to a specified x-coordinate slowly.

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

The movement on the x-axis should be smooth, i.e. it shouldn't jump from one spot to the next, but rather move to a specified x-coordinate slowly.

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

Basically, I am looking for a hypthetical method Vector2.MoveTowards that only takes an x-input.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

added 126 characters in body
Source Link
ChrisC
  • 116
  • 1
  • 10

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

The movement on the x-axis should be smooth, i.e. it shouldn't jump from one spot to the next, but rather move to a specified x-coordinate slowly.

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

The movement on the x-axis should be smooth, i.e. it shouldn't jump from one spot to the next, but rather move to a specified x-coordinate slowly.

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

Don't repeat tags in title
Source Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401

Unity: Move object continuously along y with optional movement along x

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowardsVector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

butBut this doesn't lend itself to my current requirements becsausebecause, when I set the movementTarget, I need to specify a y-component component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

Unity: Move object continuously along y with optional movement along x

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

but this doesn't lend itself to my current requirements becsause, when I set the movementTarget, I need to specify a y-component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

Move object continuously along y with optional movement along x

I am looking for a sensible way to continuously move an object downwards with constant speed while moving left or right by some amount x when the user presses the left or right arrow keys.

Basically, movement should look like this:

|
|
V Right Arrow  Key pressed
    |
    |
    |
    V Right Arrow key pressed
        |
        |
        |
        V Left Arrow Key pressed
    |
    |
    |
    V

What I am having trouble with is moving along the x axis independently of the y-axis.

I have another project where I handled movement towards a certain goal with Vector2.MoveTowards

void Update()
{
    float step = 1 * Time.deltaTime;
    transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
}

I would use this by setting the object's movementTarget

But this doesn't lend itself to my current requirements because, when I set the movementTarget, I need to specify a y component, which leads the object's velocity on the direction to become zero once the movementTarget is reached, but I need the object to move continuously along the y-axis.

I'm not sure if I'm making myself clear, so please ask questions if more information is needed.

added 293 characters in body
Source Link
ChrisC
  • 116
  • 1
  • 10
Loading
Source Link
ChrisC
  • 116
  • 1
  • 10
Loading