How do I - Randomize Object Movement

Just started using Construct 2? Post your questions here

Post » Sun Jun 19, 2016 10:33 am

Hello all.

I am currently working on a game prototype that is akin to Shark Evolution or Chicken Evolution. In those games, the objects have random idle movements that they do at occasional intervals independent of all other objects on the layout.

I have managed to emulate to a certain degree the random movements with the below event chain:
Image

However, while the objects do move in random directions at random speeds, they move together. When the fifteen second mark hits they both will shoot off in a random direction, instead of doing so separately. Any ideas on how to make it so that the object chosen to move is random out of those that are available on the layout?

Thanks in advance.

Edit: I've come to discover that the mobs only shoot off in a random direction when they hit/land in certain invisible barriers. Basically what I'm now needing to know is how to make it so that when the objects enter a specific invisible area they are repelled back toward the main area. I have collisions set to off due to the fact that the objects need to be able to wander around and travel on top one another, otherwise they fuse automatically by themselves and I'm trying to avoid that.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Sun Jun 19, 2016 1:56 pm

For your first Problem a possible solution:

- Give the stg1lv1 object a variable called timer
- Set the timer to a random value at creation
- Each Second Subtract 1 from this timer
- Make a condition if instance variable timer is <= 0 -> Change direction, speed -> set timer to random (value1,value2)

For the second question

i am not sure if you have disabled the collision detection or the physical bullet collision.
if collision detection is on you could make an on collision with another object event, then calculate the angle based on your objects position relative to the barriers position and then reverse it and set it as the new angle of movement.

Hope that helps :)
B
19
S
7
G
1
Posts: 222
Reputation: 2,551

Post » Sun Jun 19, 2016 3:03 pm

I have turned collisions back on and successfully managed to make it so that when the objects touch the border, they bounce back off of it. Your suggestion for individual movements is interesting, and I will take a crack at it.

I'm still having the problem of being able to drag the mob inside of the invisible area. They freeze and are unable to move, instead of being repelled back toward the center of the layout. I'm unsure how to go about fixing that.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Tue Jun 21, 2016 6:02 am

oxBrandxo wrote:...they both will shoot off in a random direction, instead of doing so separately.


Try adding a "For each" condition.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Tue Jun 21, 2016 12:04 pm

The problem of independent movement has been solved, though I'm still having issues with being able to put objects in an area they shouldn't be and being unable to make them move out of that area on their own.

Having said that I hit the event limit of the free edition last night, so I'm screwed until I can get the personal license.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Wed Jun 22, 2016 7:34 am

By what manner are you putting objects in areas they shouldn't be? Are they supposed to wander out gradually or teleport out instantly?

You might be able to simplify/refactor your project, 100 events can go a long way. Otherwise, you can also try working on different parts of your game or mechanics in separate projects.

If you post a capx, that would make it a lot easier to help with your problem, and also maybe compact your event sheet too.
Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Wed Jun 22, 2016 5:39 pm

I did intend to do that, but I'm fairly certain that I'm going to be able to acquire a license on Friday.

As for your question, the objects are being dragged into the area. They are indeed meant to wander out on their own.

I will post a capx soon, any and all comments (constructive) are welcomed and appreciated.
B
7
S
1
G
1
Posts: 12
Reputation: 899

Post » Wed Jun 22, 2016 8:44 pm

Mistakes were made.
B
53
S
27
G
114
Posts: 1,695
Reputation: 64,438

Post » Thu Jun 23, 2016 2:49 am

Message: oxBrandxo can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
That would work perfectly. It will take me a bit of time to reverse-engineer it and understand exactly what you did and where best to apply it (I'm thinking OnFunction will be necessary), but it's a perfect example of what I needed.

The capx for my prototype can be downloaded here:
https://w w w.dropbox.com/s/xt7rkudg4maafwt/EvoPrototype.capx?dl=0 (remove the spaces in the www). Any helpful tips are appreciated.

Edit: I updated the file a couple minutes ago, managed to free up about 27 event slots. Having issues implementing the suggestion in a working manner. The corners are extremely screwy...

Edit 2: Managed to get the movement working properly. I had to add an invisible, uninteractable object in the center of the layout and set the object angle to its position.
B
7
S
1
G
1
Posts: 12
Reputation: 899


Return to Beginner's Questions

Who is online

Users browsing this forum: sean080 and 0 guests