Pillar movement problems

Updated on March 18, 2016 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
6 on March 13, 2016

Hey guys! I have been practicing Unity a bit more, as well as following tutorials across both YouTube and the internet in general. I decided to make a game inspired by Flappy Bird; not the most original thing to do now but it is a simple concept and something I can practice making to nurture my skills.

As some of you may know I am not too keen about programming. Most of the code I have used in my project are snippets from other peoples code that they have written. I want to make two obstacles (a pillar from the top and a stack of crates at the bottom) to move towards the player at different heights, but they keep merging into one another despite defining preset locations for them to stay. Here is the code I have as of the moment:

 using UnityEngine;
 using System.Collections;
 public class MovingObstacles : MonoBehaviour
 {
 //Velocity of the Obstacle
 public Vector3 velocity;
 //Distance Between Obstacle1 & Obstacle2
 public Vector3 distanceBetweenColumns;
 void Update()
 {
 moveObstacle();
 }
 //Move the obstacle
 private void moveObstacle()
 {
 //The obstacles are going from Right To Left
 this.transform.position = this.transform.position + (velocity * Time.deltaTime);
 //If the Obstacle reaches the end of the Screen
 if (this.transform.position.x <= -13.5f)
 {
 //if not, increase the distance between Columns when we reach the -13.5 X position
 Vector3 TemPosition = this.transform.position + distanceBetweenColumns;
 //Change the Y position to a Random One.
 TemPosition.y = Random.Range(-5f, 5f);
 //And the move the Pipes to that position.
 this.transform.position = TemPosition;
 }
 }
 }
 

I apologise if it sounds like I am asking people to do the coding for me but I am completely stumped! 😮

Additionally I wish to make the background move and repeat so it looks like the player is moving when they are not actually moving; a parallax effect I think? I do not know how to make this happen though.

  • Liked by
Reply
1 on March 13, 2016

Hi there,
I’m not sure how to help in terms of the pillar movement I’m afraid.
But for the parallax scrolling have you checked out the Brackeys tutorial video for it?
i believe it’s episode three of the “how to make a 2d platformer” series. 
Here
(I hope this is what you meant)

on March 13, 2016

I tried it but the content is outdated now. Even copying the premade scripts does not work.

Show more replies
  • Liked by
Reply
Cancel

Thought I would bump this thread since I have not received many answers from the community. Sorry for sounding a bit desperate but I am panicking a little.

Devoted
on March 15, 2016

You have to go through the script , copy pasting is not practicing scripting. 
Basic steps – go through script – google – repeat till you dont find answer . 

At a specific point were you find no clues/answer ask.

Did you check the unity 2d shooting example (The bazuka one ?) It have simple script for parallax , which still works.

Well dont give up learning , but i really feel like you should follow some tutorials . Well i started from brackeys 🙂 , you can even !

on March 15, 2016

I mainly copied the scripts to see the structure, and I also tried editing them to see what happens, so I could add comments to explain them. I tried searching but only twenty percent of those searches are relevant or helpful.

The 2D Platformer script works but I do not know to initialise that and the tapping function upon the press of an in-game button.

I will continue practising but I do not find it enjoyable; it is rather stressing.

Show more replies
  • Liked by
Reply
Cancel

Bumping again. Tried a few other ways to make the pillars function as they should but I cannot think of a way to make them work!

  • Liked by
Reply
Cancel