Hello
Could someone make me a script that:
-Looks at the player when they get too close
-Then chases them
-Then when they touch the player the player dies
and make it easy for me to install, i have tried making so many scrips but i cant get it to work:rage:
Thanks
Mensley:)
look at the asset store, there are some AI scripts that you can buy!
Otherwise you need to do it your self!
Just try it, and if you have any problems post your code here and we will help you out.
P.S. there are also tutorials out there. just google it
Iām not going to write it all for you but hereās some of the basics in pseudo code.
void Update()
{
//Check if the player is close enough, use either a second collider or distance formula with
//Ai's tranform and the players
//Rotate towards player
if(withinDistance)
{
//Look up RotateTowards and moving forward
}
}
void OnCollisionEnter(Collision col)
{
Destroy(col.gameObject);
}
There is a tutorial at Unitygems that does most of what you want. The topic is on rotation, but you should follow it just the same.
How far are you going to get if everyone makes your scripts for you?
How much will you have achieved in a few years if everyone makes your scripts for you?
Start now and build your own future, stop relying on others.
O.o
Thatās the farthest a thread named āMake my script for meā has ever gone with purely civil and helpful answers. That quote is usually the first response.
I Have Tried And Tried with tutorials with the scrips i was given at the unity training but it is just not working for me so i have asked for some help that is all
Just want a bit of help i am only learning this
Asking for help is fine. Asking for someone to write scripts for you, is not the point of this forum. Those requests should go under commercial or collaboration.
Post the scripts you have and where the problems are, and we would be happy to take a look with you.
Did you even look at the tutorial I linked? It ends up with a playable environment with sleeping monsters that wake up when you get close or look at them and chase you. It has downloadable code even. Are you saying the tutorial didnāt work and the code is broken? Or did you not even bother checking it out because you saw the word tutorial and figured that it was work that you were going to have to do?
It doesnāt seem like you are trying to learn this. It seems like you are being lazy and want someone else to write scripts for you.
I havenāt had a chance i am about to look i have had a lot of homework as i am only in yr 7 and today i have the day off
i have just tried a simple script on that link but it didnt work
error message
Enemy1 script has not fineshed complition yet. please wait till it has complited
any ideas
I have just tried making a new script and there was some erros that i dont no how to fix here is my script
using UnityEngine;
using System.Collections;
public class EnemyAI : MonoBehaviour {
public Transform target;
public int moveSpeed;
public int rotationSpeed;
private Transform myTransform;
void Awake(){
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag(āPlayerā);
target = go.transform;
}
// Update is called once per frame
void Update () {
Debug.DrawLine(target.position, myTransform.position, Color.yellow);
//Look at target
myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position, rotationSpeed), rotationSpeed * Time.deltaTime);
//Move towards target
myTransform.position += myTransform.forward * Time.deltaTime;
}
this script is just for moving the enemy and there is some sort of error in the look at target section it is a c#script
any ideas
Thereās literally no way anyone can help if your error message is āThereās some kind of errorā.
Enable your console (Window > Console) and read off the actual error. Or, if thereās no error but the behaviour is wrong, describe the desired behaviour and the actual behaviour in clear terms.
there are 4 errors and they are stopping me from using the game
1)
Assets/EnemyAI.cs(28,90): error CS1502: The best overloaded method match for UnityEngine.Quaternion.LookRotation(UnityEngine.Vector3, UnityEngine.Vector3)' has some invalid arguments 2) Assets/EnemyAI.cs(28,90): error CS1503: Argument
#2ā cannot convert int' expression to type
UnityEngine.Vector3ā
3)
Assets/EnemyAI.cs(28,51): error CS1502: The best overloaded method match for UnityEngine.Quaternion.Slerp(UnityEngine.Quaternion, UnityEngine.Quaternion, float)' has some invalid arguments 4) Assets/EnemyAI.cs(28,51): error CS1503: Argument
#2ā cannot convert object' expression to type
UnityEngine.Quaternionā
This is always were i get stuck i cannot fix errors as half the time i do not no what they are talking about
Please use code tags for codes next time. More info on that here: http://forum.unity3d.com/threads/143875-Using-code-tags-properly
On-topic, your problem lies here:
Quaternion.LookRotation(target.position - myTransform.position, rotationSpeed)
LookRotation takes in two arguments, both arguments are Vector3. The variable rotationSpeed is not a Vector3 so Unity throws an error. You can read up on Quaternion.LookRotation here: Unity - Scripting API: Quaternion.LookRotation
These are basic C# fundamentals that need to be understood before you continue programming.
Iād suggest doing a C# course first, we canāt explain these errors to you because they are easily learnt and a part of the language fundamentals.
Buy a one month subscription to lynda.com and do this c# video courseā¦
http://www.lynda.com/Visual-Studio-2010-tutorials/C-Essential-Training/83789-2.html
Good luck
Ouch.
Butā¦ I agree with most of the commenters. This is supposed to be a supportive community, not some kind of free coders-for-hire nest. Whether you want or not to learn how to code, itās pretty offensive to some people to come and say āhey, I donāt know how to and I need it done. Would you be so gentle to make it for me? (ah, by the way, expect no reward)ā. Although I differ from Meltdownās statement. We could explain those errors you get, but I think itād be pointless, since you donāt seem to know how to program, even you donāt seem interested.
well that wasnt true i do want to learn and the way i learn was always diffrent to others i get exampes then take bits and pieces from i but that is in other things i didnt want whole big script just something to get ne started
/thanks mate it is looking at me and moving towards me although is there a way to make him go faster when i click on him there is an area to do that under the sripts name but no mater how fast i tell it to go it is going at snail speed i am going at about 10 and i would like it to go 8
any sugestions