Could someone writte me simple script that moves object to certain node (empty object)?
I would just like that fish would move from left side of screen to right side only on X coordinate.
I am not programmer and i would really need it to build up demo prototype.
Oh sorry i forgot to add that i dont want this on player fish. It is “enemy fish”. So it just should move from right side to left side of screen with some speed. Could you writte this kind of script please? And there is no need to call certain GameObject for it i guess.
Well I’m not sure if you need a GameObject or not, try it out, if you don’t need a GameObject just remove every code before function Update it should work I think.
p.s
(Vector3.left* 10 *Time.deltaTime); 10 is the speed the fish will move so change it to whatever speed you want the fish to move at.
oh I forgot to mention that you need to attach a Rigidbody to your enemy fish which you can do by selecting the enemy fish going to Component->Physics->Rigidbody after you attach it disable gravity make sure to check all the boxes in the Constraints section.
hmm, well try changing the vector3.left to something different like vector3.right or vector3.up or vector3.down maybe change the speed variable to 1 or so if not a decimal value might help
It sounds like you want to build an AI script rather than just a move script. You say it is an “Enemy Fish”, this kind of tells us that it is not going to be nice for our player. Question is, is this a Frogger type of game, where the fish just constantly move in one direction or the other, or does it actively seek out the player?
Sadly, I just wrote a writeup on basic AI function for a zombie, but it actually can be used anywhere you have a seek and destroy AI needed.
As far as the script from above… You would probably want to use Mathf.Repeat for cycling and Mathf.PingPong for ping ponging.
//This script is placed on the fish....
var fishSpeed : float = 10.0; // number of seconds it takes to get from min to max
var yPlane : float=0.0;// position on the screen up and down.
var minX : float=-20.0;// from here
var maxX : float=20.0;// to here
function Update()
{
var x=minX + Mathf.Repeat(Time.time / fishSpeed * (maxX-minX), (maxX-minX));
//print(Array(Time.time / fishSpeed, Time.time * (maxX-minX), fishSpeed, maxX-minX));
transform.position=Vector3(x, yPlane, 0);
}