2D Moving cloud

Hello everyone,

I am working on a 2D game and I am attempting to create an animation of a cloud moving from left to right on the X axis across the screen. The cloud is needing to appear off screen on the left and then move and clear the screen on the right before destructing and repeating. I’m a little new to using unity so I’m not sure what components of the scripting I would need to use to achieve this. Any ideas?

there are many ways to move an object.

translate for any transform
force for a rigid body
move for character controls

each will do the same thing, you just need to figure out what works best for you.

Try
function Update()
{
transform.Translate(Vector3.right);
}

attach that script your cloud. see what happens.

oops.
double post.
d’oh!

Code works to an extent. What I am needing now is to:

  1. Slow it down a bit, since the cloud image flies off the screen faster than the delorean.
  2. I need to have it randomize between 2-3 different cloud images.
  3. I need to have it start out of view and end out of view then repeat.

Any thoughts?

code is not working

||||
just multiply the vector but a factor of less than 1.
so…
transform.Translate(Vector3.right * 0.3);

|||
var image : Texture[ ];
var imageArray : Array;

function Start()
{
imageArray = new Array (image);
pickCloud();
}
function pickCloud()
{
var randomImage : float = Radom.Range((0, 1));
renderer.material.mainTexture = imageArray[randomImage];
}

this is a little rough on the random side, but hopefully you get the picture.

||||

function Start()
{
transform.position = Vector3(-100, 0, 0);
}

to get it to end out of view, make it move as you have done.
Then you could have a trigger, out of view, on the other side, that when cloud enters…

function OnTriggerEnter(other : Collider)
{
if(other.tag == "cloud")
transform.position = Vector3(-100, 0, 0);
}

what is this? if i have a mesh of cloud and want to move that from left to right and then want to repeat that process again and again what the method? and where and how to apply the above scripts?

anybody there?

var speed: int;
var offscreen: float;
var spawn: float;
var highest: float;
var lowest: float;


function Update () {
//amount to move cloud
amtToMove = Time.deltaTime *speed;
//move enemy
transform.Translate(Vector3.right * amtToMove);
//respawn with random Y
if (transform.position.x <= offscreen) {
	
	transform.position.x = spawn;
	transform.position.y = Random.Range (highest , lowest);

	}

imageArray = new Array (image);

pickCloud();

}

function pickCloud()

{

var randomImage : float = Radom.Range((0, 1));

renderer.material.mainTexture = imageArray[randomImage];

}

didn’t test so don’t shoot…

ah and drag this on your cloud mesh/particleSys

i had this and in this i moved camera instead of clouds but i want clouds to move and the script you provided is full of bugs :frowning:

825614–30722–$clouds.rar (15.6 KB)

check it out

I checked out the rar and whatever is in there is full of bugs. Missing scripts, shaders not applied to anything, purple particles.
If you want help, be more specific. Jister and renman were already nice enough to provide (working) scripts.

dude that’s not even close… that’s just gameboys208 broken stuff without any changes… :frowning:
and please export a unitypackage instead of just raring it. nothing is connected anymore…

here:

edit: the bug in my script was off course the <= which should be >…
btw if you can get this to work maybe you should start with one of unity’s superb tutorials!! :wink:

827097–30817–$movingCloud.unitypackage (21.7 KB)

i don’t know how to make unity package :frowning: that’s why i uploaded rar

here ix the package check it out

827168–30818–$cloud fly.unitypackage (43.1 KB)

hey i applied your code but its not working on prefab check my unity package in that you’ll see the cloud prefab try your own and check its not working

just import that unitypackage in your project. it’s a full example of what you need, just replace the particle system with yours

i did but object is moving but when i replace that object with cloud prefab i wont work check my cloud prefab in my unity package it posted it earlier

particle effect are not following the path of my cloud prefab :s

check my problem please