|
Hello, I am moving an object in a random 360 degrees direction but sometimes the speed of the object is slowing when the randomed direction is too low. Here's my code. Now, whenever the direction returns a low randomized vector3, the movement of the object will be too slow. Any ideas to make the movement at a constant speed? Thanks in advanced! Patrick
(comments are locked)
|
|
Use Random.onUnitSphere or .normalize the direction you are creating at the moment. Hi Mike, Thanks for answering. The direction is normalized and the object is moving in a 360deg motion. My only problem is solving it's speed issue. When let's say the randomed direction is
Aug 02 '12 at 10:01 AM
trickpirata
If you normalize the direction (with .normalized) then it will always be a length of 1 - I don't see a .normalized in your code. Random.onUnitSphere produces a normalized direction automatically - but you don't want y movement so you are better off with a .normalized.
Aug 02 '12 at 10:03 AM
whydoidoit
Hello Mike, My random.range is from -1.0 to 1.0 same as some other normalized values. But anyway I've changed my script to this I guess I need to user rigidbodies for this?
Aug 02 '12 at 10:15 AM
trickpirata
:) You are dancing around the solution! Random.range like you have it will make it inside a unit sphere but .normalize will put it on the sphere. If you do it like you are with y = 0 then it will be on the unit circle (always length 1).
Aug 02 '12 at 10:19 AM
whydoidoit
That should do it. LOOOOL! Thanks. I thought Random.Range(-1.0f, 1.0f) is equal as the values in .normalized. Thanks Mike!
Aug 02 '12 at 10:30 AM
trickpirata
(comments are locked)
|
