Hi,
I created enemy (a ball) that follows my player hit it or touch it and player dead or decreased power.
but i can’t able to script it properly. I use this code in my Sphere(Ball Enemy to gave it AI) But it does not rotate & i didn’t know how to add rotate line or something in my code) can you please help me .
I need real-time rotation when it’s following my player . With this script the enemy does not rotates it follows up my player just track or drag like . it does not rotating like the ball walking . Please help me .
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
You need to get rid of “transform.LookAt” since it’s telling the ball to rotate toward the player. If you need to get the direction to the player use Vector3.Normalize(Player.position - transform.position).
It’s not roration perfectly and it’s AI not works anymore perfect after deleting - transform.LookAt(Player);
and insert - Vector3.Normalize(Player.position - transform.position); instead .
var Player : Transform;
var MoveSpeed = 4;
var MaxDist = 10;
var MinDist = 5;
when i try to erase [/ myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed * Time.deltaTime); ] then after half rotation enemy ball stops stand in one position and starts small jumps .
You can do this automatically by picking the icon in the tool bar when writing your post, or by using square brackets [ ] with the words code at the beginning and /code at the end inside these square brackets.
For more information, please see the sticky post in scripting and support on how to use code tags.
Personally, you can try to manually determine the movement and rotation of the sphere, but I would simply use forces, and let the ball rotate on it’s own.
Look at the learn tab of the unity website and watch the “roll a ball” project for examples.
If it were me, I would take the point where my ball is, and find the point where my player is, which will give you the direction between them, and then I would add force on the ball, pushing it towards the player.