# Move to random point

Get help using Construct 2

### » Sun Feb 09, 2014 8:51 pm

I would like to implement a movement where the object picks a random point on the screen moves to it and once its there picks another random point. I would also like to speed the object up after each movement. I have been trying to do with with sine waves but can't seem to figure it out. Anyone have any ideas?Pixelgent2014-02-09 21:53:11
B
3
Posts: 4
Reputation: 183

### » Mon Feb 10, 2014 1:25 am

Its rather easy to do. And can be done several ways, so ill just comment on one of them here.

If you make an event that triggers every X nr of ticks/Seconds depending on what you like.

Object.X = random(WindowWidth)
Object.Y = random(WindowHeight)

Since you want it to jump faster and faster, you can add a global variable called "Speed = 15" which will simulate seconds in this example.

In the event "Every X seconds" you set the value to this variable:

Every <Speed> seconds
...make object jump

Then in the end of this you just reduce "Speed" with whatever value you feel like.

So the complete code would look something like this:

Global Speed = 15

Event:
Every <Speed> seconds

Object.X = random(WindowWidth)
Object.Y = random(WindowHeight)

Set Speed to Speed - 1 (Will reduce it by 1 second every time it jumps.)

nimos1002014-02-10 01:27:00
B
45
S
12
G
3
Posts: 1,209
Reputation: 7,547

### » Mon Feb 10, 2014 6:20 am

Im sorry, while this does actually help a bit i think i was unclear, this seems to make the object jump between 2 point when actually i want it to tween between the two faster and faster with every movement.
B
3
Posts: 4
Reputation: 183

### » Mon Feb 10, 2014 6:57 am

You could use lerp or a custom movement behaviour. I'll give you an example using the custom behaviour.

var1 = 1
Trigger once
..(set varx value choose (x1,x2...))
..(set vary value choose (y1,y2...))
..var1 = 0

var1 = 0
Trigger once
..(create object at x,y)
..var2 =1

var2 = 1
everytick
..(accelerate custom movement var3 towards (varx, vary)
..add 30 to var3 (adjust the amount here to vary the speed)

object x = varx
object y = vary
Trigger once
..set var1 to 1
..set var2 to 0
..set var3 to 0rekjl2014-02-10 07:01:32
B
46
S
23
G
31
Posts: 693
Reputation: 20,637