mirror of
https://github.com/BlackMATov/unity-iso-tools.git
synced 2026-01-06 11:50:56 +07:00
physics wip
This commit is contained in:
25
Assets/IsoTools/Examples/Scripts/CircleFly.cs
Normal file
25
Assets/IsoTools/Examples/Scripts/CircleFly.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class CircleFly : MonoBehaviour {
|
||||
public float FlyRadius = 150.0f;
|
||||
public float FlySpeed = 1.0f;
|
||||
|
||||
Vector3 _start_pos;
|
||||
float _fly_timer;
|
||||
|
||||
void Start() {
|
||||
_start_pos = transform.position;
|
||||
_fly_timer = 0.0f;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
_fly_timer += FlySpeed * Time.deltaTime;
|
||||
transform.position = new Vector3(
|
||||
_start_pos.x + Mathf.Cos(_fly_timer) * FlyRadius,
|
||||
_start_pos.y + Mathf.Sin(_fly_timer) * FlyRadius,
|
||||
_start_pos.z);
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
@@ -1,24 +0,0 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class CircleFlyCamera : MonoBehaviour {
|
||||
|
||||
public float FlyRadius = 150.0f;
|
||||
public float FlySpeed = 1.0f;
|
||||
|
||||
Vector3 _start_pos;
|
||||
float _fly_timer;
|
||||
|
||||
void Start() {
|
||||
_start_pos = transform.position;
|
||||
_fly_timer = 0.0f;
|
||||
}
|
||||
|
||||
void Update () {
|
||||
_fly_timer += FlySpeed * Time.deltaTime;
|
||||
transform.position = new Vector3(
|
||||
_start_pos.x + Mathf.Cos(_fly_timer) * FlyRadius,
|
||||
_start_pos.y + Mathf.Sin(_fly_timer) * FlyRadius,
|
||||
_start_pos.z);
|
||||
}
|
||||
}
|
||||
@@ -2,32 +2,32 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class IsoAutoController : MonoBehaviour {
|
||||
public float StepTicks = 0.5f;
|
||||
public float StepRndTicks = 0.5f;
|
||||
public class IsoAutoController : MonoBehaviour {
|
||||
public float StepTicks = 0.5f;
|
||||
public float StepRndTicks = 0.5f;
|
||||
|
||||
void Start() {
|
||||
StartCoroutine("Move");
|
||||
}
|
||||
void Start() {
|
||||
StartCoroutine("Move");
|
||||
}
|
||||
|
||||
WaitForSeconds RndWait() {
|
||||
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks));
|
||||
}
|
||||
WaitForSeconds RndWait() {
|
||||
return new WaitForSeconds(StepTicks + Random.Range(0.0f, StepRndTicks));
|
||||
}
|
||||
|
||||
IEnumerator Move() {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
for (;;) {
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
IEnumerator Move() {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
for (;;) {
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
yield return RndWait();
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
@@ -1,30 +1,39 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace IsoTools { namespace Examples {
|
||||
public class IsoController : MonoBehaviour {
|
||||
void Update () {
|
||||
var iso_object = gameObject.GetComponent<IsoObject>();
|
||||
if ( iso_object ) {
|
||||
if ( Input.GetKeyUp(KeyCode.LeftArrow) ) {
|
||||
iso_object.Position += new Vector3(-1, 0, 0);
|
||||
namespace IsoTools {
|
||||
namespace Examples {
|
||||
public class IsoController : MonoBehaviour {
|
||||
void MoveIsoObject(Vector3 dir) {
|
||||
var iso_object = GetComponent<IsoObject>();
|
||||
var iso_rigidbody = GetComponent<IsoRigidbody>();
|
||||
if ( iso_rigidbody ) {
|
||||
iso_rigidbody.Rigidbody.velocity = dir;
|
||||
}
|
||||
else if ( iso_object ) {
|
||||
iso_object.Position += dir * Time.deltaTime;
|
||||
}
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.RightArrow) ) {
|
||||
iso_object.Position += new Vector3(1, 0, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.DownArrow) ) {
|
||||
iso_object.Position += new Vector3(0, -1, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.UpArrow) ) {
|
||||
iso_object.Position += new Vector3(0, 1, 0);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.A) ) {
|
||||
iso_object.Position += new Vector3(0, 0, 1);
|
||||
}
|
||||
if ( Input.GetKeyUp(KeyCode.Z) ) {
|
||||
iso_object.Position += new Vector3(0, 0, -1);
|
||||
void Update () {
|
||||
if ( Input.GetKey(KeyCode.LeftArrow) ) {
|
||||
MoveIsoObject(new Vector3(-1, 0, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.RightArrow) ) {
|
||||
MoveIsoObject(new Vector3(1, 0, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.DownArrow) ) {
|
||||
MoveIsoObject(new Vector3(0, -1, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.UpArrow) ) {
|
||||
MoveIsoObject(new Vector3(0, 1, 0));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.A) ) {
|
||||
MoveIsoObject(new Vector3(0, 0, 1));
|
||||
}
|
||||
if ( Input.GetKey(KeyCode.Z) ) {
|
||||
MoveIsoObject(new Vector3(0, 0, -1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}} // namespace IsoTools::Examples
|
||||
}
|
||||
Reference in New Issue
Block a user