Lerp Random Position - Within Original Vector3
Hello,
I'm trying to randomly move (iTween) an object to randomly generated values, but I want the object to remain within a certain position, which is its initial starting position.
The problem with just using 'Random.Range' is that the object will eventually move completely away from it's original position. (Say Random.Range keeps getting 10, 10, the object will just keep moving top left).
Essentially, I'm almost looking for a 'shake' effect; so the object will still retain within it's original position.
Any ideas how I can achieve this?
Thanks.
Answer by cjdev · Sep 07, 2015 at 09:56 PM
You'd have to create an offset within the Random.Range function. Say you had an object starting at x=0 and wanted to 'shake' between -10 and 10, you could do something like this: object.x = Random.Range(-10 - object.x, 10 - object.x)
;
Your answer
Follow this Question
Related Questions
My sprite looks like it is haveing a seizure. What am I doing wrong? 1 Answer
Spawning an object betwheen two positions (while making sure whole object is within area) 1 Answer
objects of same parrent random scale/size(xy and z) 0 Answers
Translating an Object to a Random Endpoint,Moving an Object to a random endpoint 0 Answers