14
2012
Walking Block Rotation

Testing rotating / walking block code.. (as seen in many puzzle games)
Current progress:
– Screenshot: Step.1 and Step.2 (going towards right direction)
– Can walk one direction..
– Need to add smooth movement (now it rotates 90 degrees instantly)
*This one failed.. not going to fix it
(if you want the demo, I can post.. but it only works in 2 directions)
Source (javascript)
public var pivotball:Transform[];
function Update ()
{
if (Input.GetKeyDown("a")) // left
{
// function RotateAround (point : Vector3, axis : Vector3, angle : float) : void
var axis = Vector3(0,0,1);
var n = 0;
// which point is lowest, in that direction?
for (var i:int=0;i<pivotball.length;i++)
{
if (pivotball[i].position.y<transform.position.y)
{
if (pivotball[i].position.x<transform.position.x)
{
n=i;
break;
}
}
}
transform.RotateAround (pivotball[n].position,axis, 90);
}
if (Input.GetKeyDown("d")) // right
{
var n2=0;
for (var i2:int=0;i2<pivotball.length;i2++)
{
if (pivotball[i2].position.y<transform.position.y)
{
if (pivotball[i2].position.x>transform.position.x)
{
n2=i2;
break;
}
}
}
var axis2 = Vector3(0,0,1);
transform.RotateAround (pivotball[n2].position,axis2, -90);
}
if (Input.GetKeyDown("w")) // up
{
var n3=0;
for (var i3:int=0;i3<pivotball.length;i3++)
{
if (pivotball[i3].position.y<transform.position.y)
{
if (pivotball[i3].position.z>transform.position.z)
{
n3=i3;
break;
}
}
}
var axis3 = Vector3(1,0,0);
transform.RotateAround (pivotball[n3].position,axis3, 90);
}
if (Input.GetKeyDown("s")) // down
{
var n4=0;
for (var i4:int=0;i4<pivotball.length;i4++)
{
if (pivotball[i4].position.y<transform.position.y)
{
if (pivotball[i4].position.z<transform.position.z)
{
n4=i4;
break;
}
}
}
var axis4 = Vector3(1,0,0);
transform.RotateAround (pivotball[n4].position,axis4, -90);
}
}
Related Posts
2 Comments + Add Comment
Leave a comment
Recent posts
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
Recent Comments
- on Mesh Exploder (sources)
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by













Rolling cubes one space and one rotation at a time, with a delay:
http://answers.unity3d.com/questions/8255/rolling-cubes-one-space-and-one-rotation-at-a-time.html
using physics
https://github.com/zalo/MathUtilities/blob/master/Assets/Rolling/RollingCube.cs#L11-L15