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
- 2 Sided Lighting for Sprite Diffuse Shader
- Run webgl application locally using python
- [LudumDare53] Delivery
- Dungeon Crawler Jam 2023: Trials Of the Mage
- [GreaseMonkey] Display “Unity Version Added” info in API Docs
- Fake 3D Parallax Effect using Shader & (Pre-generated) Depth Map
- Using OpenAI API with WebRequest from Unity
- [LudumDare52] Theme: Harvest
- Painting with Compute Shader
- Draw Pseudo Hilbert Curve
- Unity Stable Diffusion plugin
- Testing Connected Component Labeling
Recent Comments
- on 2D Visibility / Shadow
- on [Asset Store] Point Cloud Viewer & Tools
- on [Asset Store] Point Cloud Viewer & Tools
- on [GreaseMonkey] Display “Unity Version Added” info in API Docs
- on [Asset Store] Point Cloud Viewer & Tools
- on [Asset Store] Point Cloud Viewer & Tools
- on LineRenderer with Outline Shader
- on UI Text TypeWriter Effect [Script]
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