Fixed a bug with multiple rotations at the same time.

Made sample actions behavior a subclass of the Actor class.

Added new subclass for the Actor - MeshActor. This actor let's the actions to modify the mesh (i.e. Skew).

Added new actions:
ActionSkewBy.cs
ActionRandom.cs
This commit is contained in:
2014-06-21 02:00:27 +04:00
parent 06e25ca6c7
commit 0450492554
10 changed files with 198 additions and 78 deletions

View File

@@ -32,8 +32,6 @@ class ActionRotateBy : ActionInterval
{
float d = dt / duration;
Vector3 tgt = delta * d;
transform.Rotate(Vector3.up, tgt.y);
transform.Rotate(Vector3.right, tgt.x);
transform.Rotate(Vector3.forward, tgt.z);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
}
}

View File

@@ -42,8 +42,6 @@ class ActionRotateTo : ActionInterval
{
float d = dt / duration;
Vector3 tgt = path * d;
transform.Rotate(Vector3.up, tgt.y);
transform.Rotate(Vector3.right, tgt.x);
transform.Rotate(Vector3.forward, tgt.z);
transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles + tgt);
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using UnityEngine;
class ActionSkewBy : ActionInterval
{
protected Vector3 skewAngles1;
protected Vector3 skewAngles2;
protected Mesh mesh;
public ActionSkewBy(Vector3 tgtAngles1, Vector3 tgtAngles2, float tgtDuration)
: base(tgtDuration)
{
skewAngles1 = tgtAngles1;
skewAngles2 = tgtAngles2;
}
public override Action clone()
{
return new ActionSkewBy(skewAngles1, skewAngles2, duration);
}
public override Action reverse()
{
return new ActionSkewBy(-skewAngles1, -skewAngles2, duration);
}
public override void start()
{
base.start();
if (!(target is MeshActor))
{
throw new Exception("You should use MeshActor class instead of Actor, if you want to skew your object.");
}
}
public override void stepInterval(float dt)
{
float d = dt / duration;
Vector3 tgt = skewAngles1 * d;
((MeshActor)target).skewAngles1 += tgt;
tgt = skewAngles2 * d;
((MeshActor)target).skewAngles2 += tgt;
}
}