#Not moving position
1 messages · Page 1 of 1 (latest)
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?
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
I think the main problem is that it is completely stuck, it doesnt move at all
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
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.
yes, it cant move by script, or manually in play mode by dragging it somewhere. The animations work, and most likely the transform.translate also works, but its being blocked by something from moving.
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);
}
}
this is how it works
Don't spoonfeed
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!
Also, == true and == false is redundant
x == false is the same as !x
x == true is just x
Exactly
i aksed chatgpt, google, i dont see any problems like mine where the gameobject is completely stuck and cant move
The rule wasn't for you
It was for Rubben, providing complete code for you to copy
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
So to see if I get this, I should suggest him what to do and let him think, right?
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
Good! Cuz yeah the main thing is to also understand what you make there
Ah.. You pointed that
Exactly. Knowing the concept behind the code, and understanding what is happening, is far more valuable than just giving code. Because they may forget the code down the line, and will no doubt need to ask for help on the same issue in the future.
Whereas if they understand the overall idea, they'll be able to reconstruct it by themselves
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
Gotcha, examples and guidance rather than giving the answer on the plate. Thanks for bringing this to my attention Yasahiro
Cool 