|
I am about a week in to Unity but reading through all the tutorials, guides and documentation I can as quickly as I can. I have what I'm sure is a simple scenario but I'm having trouble determing the method to tackle it in Unity. What I want to do is have a row of cubes roll 90 degrees and one position downward followed by a delay of 2 seconds (an arbitrary number of seconds), and then repeat. Put another way, I want the cube to roll over on its side in the direction it is rolling. From what I've gathered so far, I thought one way would be to transform the cube at set intervals:
That's rotating it, but that rotation doesn't match up with the movement in the x-axis properly, so it looks awful. How could I sync the roll to exactly match up with the x-asix movement? Should I be doing this as a RigidBody and AddMotion instead? I tried that, but the roll didn't seem predictable depending on where the block was on the plane. There are animation curves I know, but I wonder how I would sync the rotation and movement on the x-axis.
(comments are locked)
|
|
A simple solution is to do the rotation as an animation where at the end of the animation the cube has moved the +1 distance. Alternatively use Transform.rotateArount to rotate around a point on the edge of the cube you're currently rolling over. If not clear what I mean, let me know, can make an example or so. EDIT: too much fun to pass, here sample code in C# (sorry not too fond of javascript but shouldn't be too hard to convert if you need), Just create new C# class called RollCube and copy/paste code below over it. EDIT2: now have rotation done from Coroutine so we can delay after rolling to a side. Thanks for the quick answer and code for rotating and moving the cube forward at the same time. Looks great! I'm having trouble applying it though with a delay after the move. I figured I could pause it after a 90 rotation with a yield WaitForSeconds(2) but that doesn't stop it at all. My goal is to be able to start and stop the cube advancing one position at a time if a player does something, otherwise, keep moving, with a pause between moves. Am I on the right track? Any idea what's up with yield not yielding?
Nov 28 '09 at 04:41 AM
TedB
That update with the coroutine works great. I was trying to do the coroutine in JavaScript but evidently not correctly. I'll leave it as C# for now.
Nov 30 '09 at 02:51 AM
TedB
That came handy to me! Was not trying out for any of these things but obviously there was a rotation and shifting of pivot points! Thanx!!!
Jan 25 '12 at 07:58 AM
ArunChnadran
(comments are locked)
|
thanx for the conversion too!!
Jan 25 '12 at 08:49 AM
ArunChnadran
(comments are locked)
|
