Hi!
So I try to make my ball move but it keeps disappearing at times I recorded it so you guys can see what’s going on. How can I fix this issue?
Thank you in advance and happy easter!
Hi!
So I try to make my ball move but it keeps disappearing at times I recorded it so you guys can see what’s going on. How can I fix this issue?
Thank you in advance and happy easter!
Looks like it could be the y portion of the rotation and the z position.
Try starting the game, but don’t move like you normally do. In the inspector adjust the y rotation and see if it ever disappears. Then try the z position.
If one or both are the cause, make sure your code doesn’t do that.
Post your code, if you get stuck, and maybe someone can help you further.
Okay, how exacly should I adjust the y rotation? to 0?
Well, what I originally meant was you may not want to be changing that in code? Though, yes, zero would be ‘unchanged’.
Okay! I haven’t changed anything in my code or in the z column where everything is set to 0 except for scale should it be set to 0 as well?
No, I don’t think the scale matters.
Note, there’s also the z position I mentioned before, though you haven’t commented on that. I’m fairly certain that was responsible for one of the “disappearing acts”, also.
Oh right! And I click the play button and changed the position in the Y rotation and z position and the ball did disappeared when I did that.
Ya… well, just make sure your code is not changing either of those?
It doesn’t!
How do they change while you’re playing then?
The code I’ve written for the ball to move doesn’t change at all when I test play it, only all the positions in the transform section change when I try to move the ball.
Hmm… Can you post the ball moving code?
Check this thread for how to post code nicely: Using code tags properly
public class NewPiskelkontrol : MonoBehaviour
{
void Update()
{
var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
transform.Rotate(0, x, 0);
transform.Translate(0, 0, z);
}
}
Okay, so it is rotating and on the y and moving on the z…
That is code better suited for a 3d program, I would imagine.
For 2D, you’d want to move on the x-axis (in your scene). You can “rotate” your sprite left/right by using a negative/positive x-scale factor, or by using the ‘FlipX’ property.
If you’re just starting out, I’d suggest that you spend some time working on tutorials.
You can find lots of good stuff here: Unity Learn
Thank you it worked! I was wondering I have a sun I want to make spining all the time how do I do that?
You can rotate 2D objects on the z-axis. Try it out
I see thank you! Can I make so that it keeps spinning ingame? I guess I do it by making a script for it?
Yes, and yes
Alright! Then I do like I did with my ball that I mark the sun and add component and choose script?
Sure, if it’s just rotating you can have the script just change the z rotation over time.