Motor
This commit is contained in:
parent
6e96537b25
commit
1f41eaa61c
5 changed files with 77 additions and 2 deletions
47
Assets/Scripts/Motor.cs
Normal file
47
Assets/Scripts/Motor.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class Motor : MonoBehaviour {
|
||||||
|
|
||||||
|
public float speed = 10;
|
||||||
|
public Vector3 dir;
|
||||||
|
|
||||||
|
public bool randomMove = false;
|
||||||
|
|
||||||
|
void Awake() {
|
||||||
|
if(randomMove) {
|
||||||
|
StartCoroutine(randomDir());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
rigidbody.velocity = speed * dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveDir(Vector3 _dir) {
|
||||||
|
dir = _dir;
|
||||||
|
rigidbody.velocity = speed * dir.normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveTo(Vector3 dest) {
|
||||||
|
dir = (dest - rigidbody.position).normalized;
|
||||||
|
MoveDir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Stop() {
|
||||||
|
dir = new Vector3(0,0,0);
|
||||||
|
rigidbody.velocity = new Vector3(0,0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator randomDir() {
|
||||||
|
Random.seed = (int)Time.time;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
MoveTo(new Vector3(30 * (Random.value*2 -1) + rigidbody.position.x,
|
||||||
|
0,
|
||||||
|
30 * (Random.value*2 -1) + rigidbody.position.z));
|
||||||
|
yield return new WaitForSeconds(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Assets/Scripts/Motor.cs.meta
Normal file
8
Assets/Scripts/Motor.cs.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4fe625f347cd04ec0b5f461f77005c35
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
|
@ -3,7 +3,7 @@ using System.Collections;
|
||||||
|
|
||||||
public class PlayerController : MonoBehaviour {
|
public class PlayerController : MonoBehaviour {
|
||||||
|
|
||||||
public float speed;
|
public float speed = 10;
|
||||||
public float nextFire;
|
public float nextFire;
|
||||||
public float fireRate;
|
public float fireRate;
|
||||||
public GameObject shank;
|
public GameObject shank;
|
||||||
|
|
@ -42,4 +42,4 @@ public class PlayerController : MonoBehaviour {
|
||||||
void Shank(){
|
void Shank(){
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
Assets/no_friction.physicMaterial
Normal file
16
Assets/no_friction.physicMaterial
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
%YAML 1.1
|
||||||
|
%TAG !u! tag:unity3d.com,2011:
|
||||||
|
--- !u!134 &13400000
|
||||||
|
PhysicMaterial:
|
||||||
|
m_ObjectHideFlags: 0
|
||||||
|
m_PrefabParentObject: {fileID: 0}
|
||||||
|
m_PrefabInternal: {fileID: 0}
|
||||||
|
m_Name: no_friction
|
||||||
|
dynamicFriction: .400000006
|
||||||
|
staticFriction: .400000006
|
||||||
|
bounciness: 0
|
||||||
|
frictionCombine: 0
|
||||||
|
bounceCombine: 0
|
||||||
|
frictionDirection2: {x: 0, y: 0, z: 0}
|
||||||
|
dynamicFriction2: 0
|
||||||
|
staticFriction2: 0
|
||||||
4
Assets/no_friction.physicMaterial.meta
Normal file
4
Assets/no_friction.physicMaterial.meta
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 012328ad8a154434cba351198ab57633
|
||||||
|
NativeFormatImporter:
|
||||||
|
userData:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue