How i can make a random motion like These samples , by expression in maya
http://www.esnips.com/doc/1226873d-d60f-45...random-movement
http://www.esnips.com/doc/93f4e383-e35b-4d...45d/random-grid
How i can make a random motion like These samples , by expression in maya
http://www.esnips.com/doc/1226873d-d60f-45...random-movement
http://www.esnips.com/doc/93f4e383-e35b-4d...45d/random-grid
CODE
object.tx=rand(10,100)
object.tz=rand(10,100)
object.ty=rand(10,100)
Its better to use noise then random since thatway youd get the same motion form payback to playback
NO NO NO
my Mean is not that
i want my objects have smooth movement between two random point or have smooth movement
on grid space .
with rand() OR noise() , my objects have stepped movement .
You need smooth movement
yes what jooja told is corrent .. you can use noise isit ???
Noise is smooth (rand isnt) just reduce the speed of your valuechange.
Noise is just a buch of sin functions times 1/f* sin etc a few times
Thanx Jooja
I Test IT . But can you help me for random movement on grid Space .
http://www.esnips.com/doc/93f4e383-e35b-4d...45d/random-grid
Execute this in your script editor (note do this on fresh or a scene you are going to clear):
CODE
file -f -new;
sphere -p 0.5 0.5 0.5 -ax 0 1 0 -ssw 0 -esw 360 -r 0.5;
expression -s("global vector $dir=<>;\r\n"+
"if ((frame%4)==0){\r\n"+
" float $rnd=rand(1,-1);\r\n"+
" if (($rnd >0.5) || ($rnd <-0.5)){\r\n"+
" $dir=<>;\r\n"+
" }\r\n"+
" else{\r\n"+
" $dir=<>;\r\n"+
" }\r\n}\r\n\r\n"+
"nurbsSphere1.translateX=nurbsSphere1.translateX+$dir.x;\r\n"+
"nurbsSphere1.translateY=nurbsSphere1.translateY+$dir.y;\r\n"+
"nurbsSphere1.translateZ=nurbsSphere1.translateZ+$dir.z;")
-o nurbsSphere1 -ae 1 -uc all;
Very Thanx Jooja
hi everyone.
I think these great ideas would work by tweaking them a bit but these samples you linked to
are a litle trickier than they look.
by the way do u mean a 2D random motion??
if you mean so , Ive come to some cool results about that but there're still some bugs in the movement . you know a total random movement means that the object has 4 choises for direction and one of them is the reverse direction of last move so that the obj. moves stupidly and looks awfull!!.
in the samples if you notice the moving crazy obj.s dont come back.
which in this case , it takes more affort and a longer script to achive that kinda movement.
try to use guides above . by the way im working on that and after cleaning it up Ill give it out.
thats right shadow
but i can not solve this problem . this samples made in After Effects .
But in maya it is so difficult for me to create .
if anybody can help me ?
this is after effects Code for 3D Movement on grid :
origin = [10,10,0]; //upper left hand corner of grid
dimX = 8; //number of columns
dimY = 6; //number of rows
dimZ = 6; //number of planes
gap = 20; // distance between cells (pixels)
gridRate = 250; //speed (pixels per second)
holdTime = .2; //(seconds)
end = 0;
j = 0;
while (time >= end){
seedRandom(j,true);
startX = Math.floor(random(dimX))*gap + origin[0];
startY = Math.floor(random(dimY))*gap + origin[1];
startZ = Math.floor(random(dimZ))*gap + origin[2];
j +=1;
seedRandom(j,true)
start = end;
endX = Math.floor(random(dimX))*gap + origin[0];
endY = Math.floor(random(dimY))*gap + origin[1];
endZ = Math.floor(random(dimZ))*gap + origin[2];
deltaX = Math.abs(endX - startX);
deltaY = Math.abs(endY - startY);
deltaZ = Math.abs(endZ - startZ);
end += (deltaX + deltaY + deltaZ)/gridRate + 3*holdTime;
}
p1 = start + deltaX/gridRate;
p2 = p1 + holdTime;
p3 = p2 + deltaY/gridRate;
p4 = p3 + holdTime;
p5 = p4 + deltaZ/gridRate;
if (time < p1){
ease(time,start,p1,[startX,startY,startZ],[endX,startY,startZ])
}else if (time < p2){
[endX,startY,startZ]
}else if (time < p3){
ease(time,p2,p3,[endX,startY,startZ],[endX,endY,startZ])
}else if (time < p4){
[endX,endY,startZ]
}else if (time < p5){
ease(time,p4,p5,[endX,endY,startZ],[endX,endY,endZ])
}else{
[endX,endY,endZ]
}
No it isn't its virtually the same code (actually slightly shorter). Anyway i just answered the question about random motion. IM not here to do your job.
Mayas just separated into 2 categories of code one for the expression node and one for the cerateion of the network.
ease== smoothstep
tough id prefeer to write the interpolator myself.
hi there guys.
yeah joojaa's right.
tha could do it but doing it manually is better cuz you have direct control on your movement.(as well as pace of motion and step size, etc)
that's wut i prefer to do myself.
but anyway as everyone knows there's a bunch of ways an aproach can be achieved in maya.
wut im working on is using a particle as a moving obj. and then locking other objects (whatever) onto it so in this way you can adjust other things as well and give them any dynamic control you want.
actualy its the same as joojaa pointed out and there's just one thing making it a disaster and thats the direction which if you dont understand the right control of it fails and gets some funky motion.
any way you can take advantage of the same func. (ease = smoothstep)
to create your movment.
Hi everyone .
I thought this topic must be crowded while I'm away but it's (hopefully or Not)
Anyway. as i told you ( i never Promise!!) "imoh3n" (is it your name???) i did what you were looking for.
Just to show you NOTHING IS IMPOSSIBLE . Actually it didnt take me a long time but Ive been really busy so that i couldn't come here and post the code.
Explanation about the code:
It's a very simple code. I just gathered all the command so that by executing it just once , it's all done.
As i mentioned the movement is not perfectly random (thats why it's more complex than it should be) and the moving Obj. which in this case is a single particle with an emitter attached onto it , just moves further and further and never moves in the reverse dir. which just has moved in the last motion.
its pretty simple. For me that was just a small challange I'm not claiming , I just enjoy thinking about these things. Anyway i Hope it will do what you're looking for. No ,don't thank me . I learned alot doing it .
I'm also gonna upload this code in the mel section .
By the way joojaa, take it easy man, I dont think that's useful for a job. and thanx for the guide.
...
The code :
[codebox]// This long yet simple code will create a scene in which a particle moves randomly
//in for directions (in a grid) .An emitter is attached onto it so that it
//(or any other object or transform node ) will move correspondingly with it.
//Be aware that this code first opens a new scene, so execute this in a clean scene or
// a Saved one. Hope you like it. Feel free to report any buggs or give any idea to me. My highend UserID is : Shadow_maya.
//thanks and here you are:
file -f -new;
currentTime 8 ;
playbackOptions -min 8 -max 10000 ;
DisplayShaded;
viewSet -fit -ff 0.8 -krs true -an 1 -t ;
string $exp1 = "if(frame %8 == 0)\r\n{\r\nrand = trunc ( rand (0.001,4));\r\n\r\n"
+ "if ( dCode == 1)\r\n\t{\r\n\t\twhile (rand == 1)\r\n\t\t{\r\n\t\t\trand = trunc ( rand (0,4));"
+ "\r\n\t\t}\r\n\t}\r\n\t\r\n\telse if ( dCode == -1 )\r\n\t{\r\n\t\twhile ( rand == 0 )\r\n\t\t"
+ "{\r\n\t\t\trand = trunc ( rand (0,4));\r\n\t\t}\r\n\t}\r\n\t\r\n\telse if ( dCode == 2 )\r\n\t"
+ "{\r\n\t\twhile (rand == 3 )\r\n\t\t{\r\n\t\t\trand = trunc ( rand (0,4));\r\n\t\t}"
+ "\r\n\t}\r\n\t\r\n\telse\t{\r\n\t\twhile ( rand == 2 )\r\n\t\t{\r\n\t\t\trand = trunc ( rand (0,4));"
+ "\r\n\t\t}\r\n\t}\r\n\r\n\tif (rand == 0)\r\n\t{\r\n\t\tdCode = 1;\r\n\t}\r\n\t\r\n\t"
+ "else if (rand == 1)\r\n\t{\r\n\t\tdCode = -1;\r\n\t}\r\n\t\r\n\telse if (rand == 2)\r\n\t"
+ "{\r\n\t\tdCode = 2;\r\n\t}\r\n\t\r\n\telse if (rand == 3)\r\n\t{\r\n\t\tdCode = -2;\r\n\t}"
+ "\t\t\r\n}";
string $exp2 = "int $dCode = dCode ;\r\nint $rand = rand ;\r\nint $step =6;\r\nif"
+ " ($rand == 0)\r\n\t{ \r\n\t\tvelocity = <>;\r\n\t}\r\n\t\r\nelse if ($rand == 1)"
+ "\r\n\t{\r\n\t\tvelocity = <>;\r\n\t}\r\n\t\r\nelse if ($rand == 2)\r\n\t{\r\n"
+ "\t\tvelocity = <>;\r\n\t}\r\n\t\r\nelse if ($rand == 3)\r\n\t{\r\n\t\tvelocity = <"
+ "<0,0,($step)* -1>>;\r\n\t}\t\t\r\n\t\t";
particle -p 0 0 0 -c 1 ;
addAttr -ln rand0 -dt doubleArray particleShape1;
addAttr -ln rand -dt doubleArray particleShape1;
setAttr -e -keyable true particleShape1.rand;
addAttr -ln dCode0 -dt doubleArray particleShape1;
addAttr -ln dCode -dt doubleArray particleShape1;
setAttr -e -keyable true particleShape1.dCode;
dynExpression
-s $exp1
-rad particleShape1;
dynExpression
-s $exp2
-rbd particleShape1;
setAttr particleShape1.particleRenderType 4;
addAttr -is true -ln "radius" -at "float" -min 0 -max 10 -dv 0.5 particleShape1;
setAttr "particleShape1.radius" 0.6;
emitter -pos 0 0 0 -type omni -r 50
-sro 0 -nuv 0 -cye none -cyi 1 -spd 0
-srn 0 -nsp 1 -tsp 0 -mxd 0 -mnd 0 -dx 1
-dy 0 -dz 0 -sp 0 ;
particle;
connectDynamic -em emitter1 particle2;
connectAttr -f particleShape1.centroid emitter1.translate;
setAttr particleShape2.particleRenderType 0;
addAttr -is true -ln "colorAccum" -at bool -dv true particleShape2;
addAttr -is true -ln "useLighting" -at bool -dv false particleShape2;
addAttr -is true -ln "pointSize" -at long -min 1 -max 60 -dv 1 particleShape2;
addAttr -is true -ln "multiCount" -at long -min 1 -max 60 -dv 10 particleShape2;
addAttr -is true -ln "multiRadius" -at "float" -min 0 -max 10 -dv 0.38 particleShape2;
addAttr -is true -ln "normalDir" -at long -min 1 -max 3 -dv 2 particleShape2;
addAttr -is true -ln "opacity" -at double particleShape2;
setAttr -keyable true particleShape2.opacity;
setAttr particleShape2.opacity 1.0;
warning ("just go ahead and hit play and there you go!");[/codebox]
very very thanx for posting the code.
you are besiness me , all the time .
now, i have two question:
1- how can i use smoothstep code to get the result, same as ease .
2- shadow, i think, you can enhance this code to 3d random movement.
i know , you are so busy and working on long animation (navid & ...) , but i hope if you complex this mel for 3D movement.
okay
that's ok man.
Your english talents always stand me!!
I dont get wut you wanne say.
And by the way about your questionS.
I dont wanne write the whole thing with another func. when there are others of them making the life easy!!
and i Thought its now up to you to enhance it for 3d movement atleast after i gave you the code.
don't tell me you didn't get the idea of that simple movement.
as you know Im busy but I think something's wrong here.
Ok mates, I see you haven't done the 3d random movement, so on a break time i did it and its now ready 2 use.
But I'm wondering where to put the code , since i uploaded the last code in MEL download section , I think its better to update that one
Or should i post the code here, too??
Anyway i think some of u may have done it before me or atleast got the right idea to enhance the last code to 3D , Im just gonna do it to complete this topic for the topic starter's sake!!
So the code will be here and also in mel download section soon,
By the way the 2d code can be downloaded from the url below right now:
http://www.highend3d.com/maya/downloads/me...ement-4611.html
=================================
Ciao