enemys now rotate, close #16
This commit is contained in:
parent
80232d1c27
commit
eb1e15c52f
2 changed files with 32 additions and 29 deletions
|
@ -113,8 +113,8 @@ Rigidbody2D:
|
||||||
m_UseFullKinematicContacts: 0
|
m_UseFullKinematicContacts: 0
|
||||||
m_UseAutoMass: 0
|
m_UseAutoMass: 0
|
||||||
m_Mass: 1
|
m_Mass: 1
|
||||||
m_LinearDrag: 0
|
m_LinearDrag: 0.1
|
||||||
m_AngularDrag: 0
|
m_AngularDrag: 0.01
|
||||||
m_GravityScale: 0
|
m_GravityScale: 0
|
||||||
m_Material: {fileID: 0}
|
m_Material: {fileID: 0}
|
||||||
m_Interpolate: 1
|
m_Interpolate: 1
|
||||||
|
@ -157,10 +157,8 @@ MonoBehaviour:
|
||||||
m_Script: {fileID: 11500000, guid: 582bfd99a32c0ea45a7d09ef4f308d88, type: 3}
|
m_Script: {fileID: 11500000, guid: 582bfd99a32c0ea45a7d09ef4f308d88, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
victim: {fileID: 0}
|
speed: 0.7
|
||||||
agressor: {fileID: 1971451785855062}
|
rotationSpeed: 1
|
||||||
speed: 0.2
|
|
||||||
rotaionSpeedWIP: 1
|
|
||||||
--- !u!212 &212571453617041228
|
--- !u!212 &212571453617041228
|
||||||
SpriteRenderer:
|
SpriteRenderer:
|
||||||
m_ObjectHideFlags: 1
|
m_ObjectHideFlags: 1
|
||||||
|
|
|
@ -4,35 +4,40 @@ using UnityEngine;
|
||||||
|
|
||||||
public class EnemyAI : MonoBehaviour {
|
public class EnemyAI : MonoBehaviour {
|
||||||
|
|
||||||
[SerializeField]
|
|
||||||
private GameObject victim;
|
private GameObject victim;
|
||||||
[SerializeField]
|
Rigidbody2D body;
|
||||||
private GameObject agressor;
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float speed = 1;
|
private float speed = 1;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float rotaionSpeedWIP = 1;
|
private float rotationSpeed = 1;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Die destructive dumme deutsche Dungeon Diktator Drifter DLC Debakel Distribution Dokumentations - Druck Datei
|
* Die destructive dumme deutsche Dungeon Diktator Drifter DLC Debakel Distribution Dokumentations - Druck Datei
|
||||||
* */
|
*/
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void Start () {
|
void Start () {
|
||||||
|
victim = null;
|
||||||
|
body = gameObject.GetComponent<Rigidbody2D>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update() {
|
void Update ()
|
||||||
|
{
|
||||||
if(victim == null) {
|
if(victim == null) {
|
||||||
//victim = GameController.instance.GetPlayer().gameObject; // TODO testing purpose only!
|
victim = GameController.instance.GetPlayer().gameObject; // TODO testing purpose only!
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 distanceToEnemy = victim.transform.position - gameObject.transform.position;
|
||||||
|
|
||||||
// movement
|
// movement
|
||||||
agressor.transform.Translate(Vector3.Scale(( victim.transform.position - agressor.transform.position ).normalized, new Vector2(speed, speed)));
|
body.velocity = new Vector2(distanceToEnemy.normalized.x, distanceToEnemy.normalized.y) * speed;
|
||||||
|
|
||||||
//rotation
|
//rotation
|
||||||
agressor.transform.Rotate(agressor.transform.forward, Vector3.Angle(victim.transform.position - agressor.transform.position, agressor.transform.rotation * new Vector3(1, 1, 1)));
|
Vector3 localRotation = gameObject.transform.localRotation * Vector3.up;
|
||||||
|
float angleToRotate = Mathf.Round(Vector3.SignedAngle(localRotation, distanceToEnemy.normalized, Vector3.forward));
|
||||||
|
gameObject.transform.Rotate(0, 0, angleToRotate * rotationSpeed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetVictim(GameObject g) {
|
public void SetVictim(GameObject g) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue