2D Rope Swing Force

I have SwingForce script and it starting swing from left. but i couldn’t swinging from right. I did forceStrength *= -1, 0, 0 but it doesn’t forceStrength *= 1, 0, 0 what can i do for this?

using UnityEngine;
using System.Collections;

public class SwingForce : MonoBehaviour {

    public float forceStrength = 8f;
    public float maxSpeed = 15f;
    public float timePerOneSide = 2f;

    private Rigidbody2D rb;
    private Vector3 force;
    private float timer = 0.0f;


    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        timer = timePerOneSide;

    }
  
    void Update()
    {

        timer += Time.deltaTime;
        if(timer >= timePerOneSide)
        {
            force = new Vector3(forceStrength *= -1, 0, 0);
            timer = 0.0f;
        }
        if(rb.velocity.sqrMagnitude <maxSpeed)
            rb.AddForce(force);
    }

}

That syntax is invalid. Try this:

void Update() {

    timer += Time.deltaTime;
    if(timer >= timePerOneSide) {
        force = new Vector3(-forceStrength, 0, 0);
        timer = 0.0f;
    }
    if(rb.velocity.sqrMagnitude < maxSpeed)
        rb.AddForce(force);
}

it doesn’t work. same problem. it’s going to right but not going to left

I guess I didn’t fully understand what you’re trying to do with this code.

is this what you were trying to do? It’s like a toggle on a timer right?

void Update() {

    timer += Time.deltaTime;
    if(timer >= timePerOneSide) {
        forceStrength *= -1;
        force = new Vector3(forceStrength, 0, 0);
        timer = 0.0f;
    }
    if(rb.velocity.sqrMagnitude < maxSpeed)
        rb.AddForce(force);
}

i swinging rope with this code. when it is forceStrength *= -1, rope begining swing from left. but i want to startin from right. I must write forceStrength *= 1, but doesn’t work. it going to left after stopping at center and going to left again.

Well if you start the rope in the center, then it will go to the left in “timePerOneSide” seconds. Then it will reverse and go to the right for “timePerOneSide” seconds, which will put it back at the center.

So you need to start it on either the far left or far right, and get the timer long enough so that it will go all the way to the other side. Then it should loop correctly.

i put -2 to timePerOneSide but it doesn’t work again. stopped at center.