- Home /
How to make a game object constantly move right while also moving up and down like its floating?
Im trying to make a boss for my 2D side scrolling game. I have an object that contains the player and main camera and they are all constantly moving to the right. I want to add a boss to this but if its moving up and down like i made it, it wont go to the right with the main camera.
Answer by Waterpolo7 · Dec 22, 2021 at 07:43 PM
Hi, so what I make up from the image you provided, you're not changing the x-position in this script, is that meant to be? Do you want the boss to move along with the camera? Or do you want to let the camera move along with the boss? If you want the boss to move right, you could try adding this in the next line:
transform.position += new Vector3(speed * Time.deltaTime, 0, 0);
Hope this helps, but don't hesitate to point out mistakes or to reformulate the problem :)
I want it to move with the camera. I have the camera constantly moving to the right and I made the boss a child of it so it will move to the right as well. The script I have now makes the boss move up and down in a loop but while this script is active the boss doesn't move with the camera anymore and gets left behind.
Hi @COLTcolossal my answer isn't a solution then. Is it an option that the boss stays in one position relative to the camera and that you just use the camera as a reference point? In the script this would be something like:
float offset = *value*;
bossObject.transform.position = new Vector3(Camera.main.transform.position.x + offset, bossObject.transform.position.y, bossObject.transform.position.z);
This would make sure the boss follows the camera (in the middle of the screen if the offset = 0, and else it will be on another position) without changing the y-value of the position. Could you try this and report back the result? :)
Answer by AlbertDevelopment · Dec 23, 2021 at 01:31 PM
transform.position += Vector3.right * speed * Time.deltaTime;
Your answer

Follow this Question
Related Questions
Semi Dynamic Shadows 1 Answer
Transform.Position stop? 1 Answer
Object Rotating around center from Mouse Movement 1 Answer
Moving an object on the X axis corresponding to mouse movment 0 Answers
simulation of motorbike suspension 1 Answer