- Home /
Goes faster when moving to monster's transform
Hey guys! I'll explain the script below, what u need to concentrate there that it casts a ray when there's a left mouse click and the tag is terrain, so it goes to the hit.point, if the tag is "monster" it goes the monster's.position, but the problem is that when I click on the monster's tag its speed increases like mulplies 5 times faster. I have no idea why it happends, can anyone tell me why?
Also, I tried adding * Time.deltaTime(near the speed) in the Move
function, and it goes okay to the monster's position, but when I hit the terrain's tag it goes to that hit.point faster.
I doubt many are going to click on your link. It looks lazy to not transcribe your code to fit the format of this site.
I like the look of the other site better. Good job, AnaRhisT!
Answer by Mike 3 · Jun 23, 2010 at 06:06 PM
As i replied in your other post(s) - you're calling the coroutines once a frame. On top of that, each coroutine is looping, to move the object
What you need to do is something like this:
function RotateTowardsMob() {
if(target != null && Vector3.Distance(target.position, transform.position) >= 0.01){
var direction : Vector3 = transform.position - target.position;
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(-direction), 0.2* Time.deltaTime);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
}
}
for all of the ones that you're calling each frame
again, mike, RotateTowards$$anonymous$$ob is just for toating.
ur purpose was crashing my unity! i knew it! lol, i managed to solve now the problem, but the rotation is very slow, i believe i need to change the 0.2 to a higher number
mark it as solved so it doesn't clog up the system then :)
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I make many object move when I click a GUI button? I want the objects move upward. 1 Answer
Move from one object to another 0 Answers
What does the {"SplatCount" = "4"} tag do in shaders? 0 Answers
How to change volume on many audio objects with specific tag ? 1 Answer