Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
OriginalGladiator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ryan Hoppe (rmh898)
OriginalGladiator
Commits
e91488fd
Commit
e91488fd
authored
8 years ago
by
Mitchel Kovacs (mdk181)
Browse files
Options
Downloads
Patches
Plain Diff
makes enemies chase player
parent
6c8682b9
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Zookeepers Trial/Assets/Scripts/InBetweenAI.cs
+57
-0
57 additions, 0 deletions
Zookeepers Trial/Assets/Scripts/InBetweenAI.cs
with
57 additions
and
0 deletions
Zookeepers Trial/Assets/Scripts/InBetweenAI.cs
0 → 100644
+
57
−
0
View file @
e91488fd
using
UnityEngine
;
using
System.Collections
;
public
class
InBetweenAI
:
MonoBehaviour
{
private
Animator
myAnimator
;
private
Transform
target
;
private
float
speed
=
3
;
bool
moveallowed
=
false
;
double
[]
heights
=
{
-
1.40
,
1
,
3.12
,
5.33
,
7.58
};
// Use this for initialization
// Use this for initialization
void
Start
()
{
target
=
GameObject
.
FindGameObjectWithTag
(
"Player"
).
transform
;
}
// Update is called once per frame
void
Update
()
{
myAnimator
=
GetComponent
<
Animator
>();
move
();
}
public
void
move
()
{
if
(
moveallowed
)
{
Debug
.
Log
(
"moving"
);
//rotate to look at the player
//transform.LookAt(target.position);
myAnimator
.
SetFloat
(
"speed"
,
1
);
// This should probbaly reflect the actual speed
transform
.
position
=
Vector2
.
MoveTowards
(
transform
.
position
,
target
.
transform
.
position
,
speed
*
Time
.
deltaTime
);
if
(
target
.
transform
.
position
.
x
<=
transform
.
position
.
x
)
//players spot in world space as opposed to enemy "self" spot
{
transform
.
rotation
=
new
Quaternion
(
0
,
180
,
0
,
0
);
// flips enemy around to face the player on x axis only
}
else
if
(
target
.
transform
.
position
.
x
>=
transform
.
position
.
x
)
//players spot in world space as opposed to enemy "self" spot
{
transform
.
rotation
=
new
Quaternion
(
0
,
0
,
0
,
0
);
// flips enemy around to face the player on x axis only }
}
if
(
Vector3
.
Distance
(
transform
.
position
,
target
.
transform
.
position
)
<
1
)
{
moveallowed
=
false
;
Debug
.
Log
(
"collide"
);
//load combat scene
}
}
}
void
OnTriggerEnter2D
(
Collider2D
other
)
{
if
(
other
.
name
==
"Player"
)
{
moveallowed
=
true
;
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment