#Not moving position

1 messages · Page 1 of 1 (latest)

last trail
#

Its also frozen even if i put gravity scale to 1

mossy quiver
#

I don't see any errors in this part, but I'll suggest to try and not use " == true " or " == false" and instead :

void Update()
    {
        if(Action.touched)
        {
            if (!thing)
            {
                transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
                StartCoroutine(CooldownCoroutine());
            }

It is the same thing but it makes the code cleaner and easier to read. Also, can I see the whole code?

last trail
#

private int MoveSpeed = 5;
public bool thing = false;
public float a = 1;
public Animator anim;
public bool thing2 = false;
public bool thing3 = false;
public bool thing4 = false;
public Spawner Bomby;
public trigger2 Action;
public Rigidbody2D rb;
void Update()
{
if(Action.touched == true)
{
if (thing == false)
{
transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
StartCoroutine(CooldownCoroutine());
}
if (thing2 == true)
{
anim.Play("SU_25_Rotate");
Bomby.Function1();
transform.Translate(Vector3.down * MoveSpeed * Time.deltaTime);
Debug.Log(transform.position);
transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
StartCoroutine(CooldownCoroutine2());
}
if (thing3 == true)
{
anim.Play("SU_25_3");
transform.Translate(Vector3.up * MoveSpeed * Time.deltaTime);
transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
StartCoroutine(CooldownCoroutine3());
}
if (thing4 == true)
{
anim.Play("SU_25_Back");
transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
}
if(transform.position.x < 325)
{
Destroy(gameObject);
}
}
}
private IEnumerator CooldownCoroutine()
{
//StartDown
yield return new WaitForSeconds(2);
thing = true;
thing2 = true;
}
There are also 2 more countdowns, they do the same as the first but activate different bools

mossy quiver
#

So, if I understand correctly, you cannot interact with that plane and it should move around according to those "thing" bools. I suggest you to add some debug logs and check if those bools are setting right

#

[]cb

mighty widgetBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

last trail
mossy quiver
#

Maybe something like this :

  void Update()
    {
        if(Action.touched == true)
        {
            if (thing == false)
            {
                transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
                StartCoroutine(CooldownCoroutine());
                Debug.Log("thing is " + thing);
            }
            if (thing2 == true)
            {
                anim.Play("SU_25_Rotate");
                Bomby.Function1();
                transform.Translate(Vector3.down * MoveSpeed * Time.deltaTime); 
                Debug.Log(transform.position);
                transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
                StartCoroutine(CooldownCoroutine2());
                Debug.Log("Thing2 is true");
            }
            if (thing3 == true)
            {
                anim.Play("SU_25_3");
                transform.Translate(Vector3.up * MoveSpeed * Time.deltaTime);
                transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
                StartCoroutine(CooldownCoroutine3());
                Debug.Log("Thing3 is true");
            }
            if (thing4 == true)
            {
                anim.Play("SU_25_Back");
                transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
                Debug.Log("Thing4 is true");
            }
            if(transform.position.x < 325)
            {
                Destroy(gameObject);
            }
            Debug.Log("thing is " + thing);
        }
    }
last trail
gleaming prismBOT
#
Rule #9. Don't spoonfeed or ask to be spoonfed

Before asking for help, please google your issue first, attempt to solve it yourself, and then ask. You learn more this way than being spoon-fed!

fallen stream
#

Also, == true and == false is redundant

x == false is the same as !x
x == true is just x

last trail
# gleaming prism

i aksed chatgpt, google, i dont see any problems like mine where the gameobject is completely stuck and cant move

fallen stream
#

The rule wasn't for you

#

It was for Rubben, providing complete code for you to copy

fallen stream
# fallen stream Also, == true and == false is redundant `x == false` is the same as `!x` `x == ...

Also as to why:

When you use the == operator, you're checking if some assertion is true. It returns true/false already.
Suppose you have an int variable. When you do

if (someInt == 42)

What you're doing here is "someInt equals 42. is that true?"
Eventually, all conditions result in a single true or false value.

So if you have some bool, like canJump for example

if (canJump == true)

What you're doing here is pointlessly saying "canJump is true. is that true?"
When you can just do:

if (canJump)

Which asks "canJump. is it true?", making == true completely and totally redundant in all cases

#

Same for == false, leading to

if (!canJump)

Essentially: "the opposite of canJump. is it true?"
If canJump is false (which is what you're checking), the opposite is true

mossy quiver
fallen stream
#

Right. Guide the person asking, help them solve the problem on their own (with your help of course). Just dumping the solution in for someone to copy/paste isn't a way for them to learn, because they won't understand the code anyway so it also wastes your own time

#

If you help someone arrive at a solution, they'll understand it better

#

Providing code is fine, if it's example code to explain a concept

#

(as I did with the if statement thing just now)

#

because they won't understand the code anyway so it also wastes your own time
NB: I know this is a blanket statement. Sometimes people can and do understand it. But many don't, especially beginners, and this server is popular with beginners so - more often than not in this server - it's not helpful to spoonfeed

mossy quiver
#

Good! Cuz yeah the main thing is to also understand what you make there

fallen stream
#

And that is the key to programming. It's not the code, it's not memorising syntax. It's problem solving

#

Learning to problem solve is vital

mossy quiver
#

Gotcha, examples and guidance rather than giving the answer on the plate. Thanks for bringing this to my attention Yasahiro

fallen stream
#

Cool blobthumbsup