# how to replicate solid-like behavior without using solids

Get help using Construct 2

### » Wed May 21, 2014 2:05 pm

What I'm trying to is to have objects stop moving when they are moving towards each like when two solids hit, but without using the solid behavior.

This is because I'm trying to have objects like my player character and enemies not be able to pass through each other. I tried just adding solid behavior, but having moving colliding solids was a BAD idea. I used the platform vector x action, which had the player character and the enemy bounce off each other when they collided , but even that had weird results when they bounced off each other too many times.

So is there anyway to get what I want without using solid behavior, Im sure the overlapping action could help me out, but it's early morning and my brain is kinda fried so hopefully someone can help me with an answer,

B
6
Posts: 25
Reputation: 300

### » Wed May 21, 2014 3:48 pm

Use the while is overlapping condition to move your objects towards the opposite position. See the attached capx.
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### » Wed May 21, 2014 4:00 pm

You could try the custom movement behavior's push out action but that doesn't work too great for moving objects.

One idea is to treat the enemies and player as circles. Then see if they collide if any two of them have a distance between them less than the sum of their radius'. Then the overlap between them would be radius1+radius2-distance. To resolve the collision just move each object half of the overlap away from each other.

Also you'll want to either set the speed to zero, bounce the objects or only set the velocity in the direction of each other to zero. The last two can be done with the help of a vector projection:
Speed_at_angle= velocity_x*cos(angle)+velocity_y*sin(angle)
Then you can eliminate speed in that direction by:
set velocity_x to velocity_x-Speed_at_angle*cos(angle)
set velocity_y to velocity_y-Speed_at_angle*sin(angle)

or to bounce do:
set velocity_x to velocity_x-K*Speed_at_angle*cos(angle)
set velocity_y to velocity_y-K*Speed_at_angle*sin(angle)

Where K is 1 for no bounce to 2 for fully elastic bounce.

I have an example of it in the first capx in this topic:
viewtopic.php?f=148&t=91829
and a more advanced version of the walls can be found here:
viewtopic.php?f=147&t=95108&p=736233&hilit=+slide#p736233

But there are probably other ways.
B
95
S
34
G
128
Posts: 5,494
Reputation: 81,676

### » Wed May 21, 2014 5:06 pm

@R0J0hound

___~
o..O
o0
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### » Fri May 23, 2014 1:26 am

Well these replies have given me some stuff to think about, i'll try them out when i get a chance,

Thanks for all the help
B
6
Posts: 25
Reputation: 300