- Home /
AI in unity, need help
I need some help with my AI I was working on, my code below
using UnityEngine;
using System.Collections;
public class NewAITest : MonoBehaviour
{
public float motionSpeed = 1f;
void Update()
{
// Rays
Vector3 upRay = transform.TransformDirection(Vector3.forward);
Vector3 downRay = transform.TransformDirection(Vector3.down);
// Up and down motion
if(Physics.Raycast(transform.position,upRay,2))
{
transform.Translate(Vector3.back * * Time.deltaTime);
}
else if(Physics.Raycast(transform.position,downRay,2))
{
transform.Translate(Vector3.forward * 1 * Time.deltaTime);
}
}
}
Ask a question!
Also
Vector3 upRay = transform.TransformDirection(Vector3.forward);
Is it Up or is it Forward?
Vector3 upRay = transform.TransformDirection(Vector3.forward);
uh, its an orthographic game, it jus looks like its moving up, because the camera is on top of veiw
So where does down go?
Vector3 downRay = transform.TransformDirection(Vector3.down);
that's the thing, It can't move down, I can't figure that out?
Put it into words man, I'm still guessing after 33 $$anonymous$$utes!
Don't like charades :P
Answer by meat5000 · Oct 14, 2013 at 01:05 AM
You mean -Vector3.forward?
forward, up, right etc are all verbal ways of expressing a numerical vector.
0,0,1 = forward (z axis) 0,0,-1 = backward
0,1,0 = up (y axis) 0,-1,0 = down
right, but it gets stuck when it tries to move away when the ray hits something, I'm not the best on AI program$$anonymous$$g though
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Make player not be seen by AI, when player in foilage and shadows. 1 Answer
Enemy ai Multiple targets 1 Answer
Argument out of range. 1 Answer
How to make AI wonder about? C#? 2 Answers