# How do I control a simple movement

Just started using Construct 2? Post your questions here

### » Sat Nov 01, 2014 2:36 pm

This is a little embarrassing but I'm a bit stuck.

I'm very new to Construct and I'm finding the things that should be hard, easy to do... and the things that should be easy, hard to figure out!

Basically, I have this little block character on screen. He's a simple little chap, that only faces left or right.
I'm trying to figure out how to give the guy the ability to move in all 8 directions but to only face left or right while doing so.
I want him to do this in a random fashion, like he's just wandering around the screen.

How can I go about it?

(Eventually, I plan to have lots of these characters (all different colours) wondering about - do I have to program each separately, or is there a built in behaviour clone feature that I've yet to discover?)

B
7
Posts: 33
Reputation: 341

### » Sat Nov 01, 2014 3:12 pm

You could use the 8-directions behaviour
- in the properties set angle = no
and set your character mirrored through events..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 01, 2014 3:40 pm

Well, that did the basics for the movement that I was after, but how do I have it so I don't have to press the arrow keys to have the guy move?
I want the little chap to move about by himself randomly.

Thanks for the reply, by the way. Much appreciated.
B
7
Posts: 33
Reputation: 341

### » Sat Nov 01, 2014 3:48 pm

You can have 8 directions simulate control left, right, up and down..
You only have to create the conditions for it..

for example:
Give the chap instance variable movement (number)

every random(1,5) seconds
for each chap
- set chap variable movement : choose(1,2,3,4,5,6,7,8,9)

for each chap
- chap variable movement = 9
-- chap 8 direction simulate control up
-- chap 8 direction simulate control right
- chap variable movement = 5
-- chap 8 direction simulate control left

I used 1 to 9 so you can easily compare them to the numbers on the numpad..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 01, 2014 7:11 pm

That worked brilliantly, thank you.

Tell me.... is it possible to do all that from with a function of some sort.
I mean, one standardised movement method, rather than having to copy 8+ events over and over for each version of the chap sprite?

As I said earlier, I plan to have lots of these sprite mulling around but with different appearances, therefore different sprites.
B
7
Posts: 33
Reputation: 341

### » Sat Nov 01, 2014 7:17 pm

You could use the function object and put the events in there..
Then for each sprite call the function..
you could call the function with parameter choose(1,..) and use that param to set the direction instead of an instance variable..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sat Nov 01, 2014 8:06 pm

I think that may well do the trick.
Thanks a lot for the help.
B
7
Posts: 33
Reputation: 341

### » Sun Nov 02, 2014 2:45 pm

I'm confused again.
I'm learning so much bit by bit but something's gone wrong.

I've got all the actions as before, in a function.
I have the call from the function to choose (1,2,3,4,5,6,7,8,9) as mentioned before.
The little character mirrors perfectly,
But he's stopped moving!!! The direction simulate etc. lines have ceased to work!
What's gone wrong.

I even added a line after the Direction Simulate line in each action, to set x to 10, x to 20, x to 30, x to 40 etc.... and they all worked. He skipped to 10,20,30,40, etc.
But he doesn't just move like he did.

Any ideas? (I'd hate to think the little guy was just moving 1 pixel on each call!)
B
7
Posts: 33
Reputation: 341

### » Sun Nov 02, 2014 9:27 pm

Again... I figured it out.
A function was a bad idea AND I've even got multiple guys moving about.
All this I've learned in a matter of hours.
Construct 2 is mighty fine.
B
7
Posts: 33
Reputation: 341