- Home /
making own AI Basic
hey i have a question for all the Unity programmers out there.
var moveSpeed = 3.0;
var rotateSpeed = 3.0;
var distance = 1.0;
var outOfReach = 20.0;
var GameObject1 : GameObject;
function Update () {
//calling a simple move function in the update function
move = transform.TransformDirection (GameObject1.transform.position);
var Reach = outOfReach;
if (Reach >= outOfReach) {
move * moveSpeed * Time.deltaTime;
}
}
this is the basic of my AI, but it doesn't do anything... can u help me? and no i can't use the AI from the FPS tut because i make a game for school and we need to make everything by our self.
ohhh and by the way, can u take a look over this move script?
var speed : float = 3.0; var rotateSpeed : float = 1.0; var jumpHeight = 5.0; var jump = false; var jumpTime = 8.0; var flyTime = jumpTime;
function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis("Horizontal") rotateSpeed, 0); var forward : Vector3 = transform.TransformDirection(Vector3.forward); var curSpeed : float = speed Input.GetAxis("Vertical"); controller.SimpleMove(forward * curSpeed);
if (flyTime == jumpTime) {
if (Input.GetButton("Jump")){
jump = true;
}
if (jump == true) {
transform.position += Vector3(0,jumpHeight,0) * Time.deltaTime;
}
}
if(jump == true) {
flyTime -= 2 * Time.deltaTime;
}
if (flyTime <=1) {
jump = false;
flyTime = jumpTime;
}
}
@script RequireComponent(CharacterController)
Thanks
Answer by muntahu · Oct 16, 2010 at 12:38 AM
if (Reach >= outOfReach) {
move = moveSpeed * Time.deltaTime;
}
Perhaps it should be like that. By the way, you declare distance without using it.
And for the move script, what is the problem? it doesn't work or what?
no it does work, but i wanted to know if there is a more effective way to do it... the jumping that is!
see about AddForce in the documentation. this is example: rigidbody.AddForce (0, 10, 0);
Answer by StephanK · Oct 15, 2010 at 09:18 PM
It doesn't do anything because you didn't tell it to do something... Read your comment own comment and think about what you want to or more specifically what you DON'T do.
Your answer
![](https://koobas.hobune.stream/wayback/20220613075818im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Enemies Moving Through Terrain Help 1 Answer
Enemy AI With changing Player 0 Answers
Random direction with Mouse Click... 2 Answers
How to make basic AI in a 2d game? 4 Answers