Setting up simple "bounce off" using events, no behaviours

Get help using Construct 2

Post » Thu Dec 24, 2015 12:03 pm

I was wondering if anyone could point me towards setting up some bouncing off and mini mock up collisions using only events and not behaviours.

The reason is twofold, firsly to actually learn to code a bit and not just use behaviours, and secondly I am using custom movements which do not work with the bullet/solid behaviours.

I am browsing the forums now, but just thought I would ask in the meantime.

Thanks for the help.
Last edited by Solomon on Thu Dec 24, 2015 12:10 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413

Post » Thu Dec 24, 2015 12:08 pm

I guess it would consist of getting the angle between the object and the object it bounces from on collision and setting the movement angle accordingly..

Getting the angle is easy:

angle(object2.x,object2.y,object1.x,object1.y)
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

Post » Thu Dec 24, 2015 7:29 pm

Well the hardest part at the moment it seems, is that I have a box constantly moving by set x=selx+60*dt, and another box controlled by the player is to slam into it at the players discretion. On impact both boxes are to bounce off each other and move in different directions.
I have the player movement set, "just" the collision and bounce is left.

Now this I would like to do without behaviours but I cant find anything that could help me out, altough I am still searching.

Rotations arent necessary for me, only direction.

I really wish there was some explanation, Im begining to dislike the idea of having behaviours that are quite limited in their functionality in regards to custom events.
Last edited by Solomon on Thu Dec 24, 2015 8:25 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413

Post » Thu Dec 24, 2015 8:05 pm

Well, Like I said, the above expression will get the angle between the objects, to get a good bounce you will have to use that angle and the movement angle of the two objects (probably using the speed as well)..
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

Post » Thu Dec 24, 2015 8:22 pm

You can probably find something in one of my posts.

The first thing is to detect the collision which is simple enough using the "is overlapping" condition. Next you need to get the objects to not overlap. One way to do that is to move the object backward till it's no longer overlapping, another is to push out in the closest direction which could either be done with some creative checking the around the sprite or using the Separating Axis Theorem (SAT) algorithm. The final thing to do is the actual bounce, usually that requires the normal or angle of the edge where the two objects meet. SAT can provide this or you can treat the objects as circles and utilize the angle between them as LittleStain said.

how-do-i-force-the-sprite-to-bounce-with-right-angle_p985939?#p985939
viewtopic.php?f=147&t=121599&p=867906&hilit=bounce#p867906
B
85
S
27
G
85
Posts: 5,066
Reputation: 57,866

Post » Fri Dec 25, 2015 12:39 pm

@Littlestain
@R0J0hound

Thanks for the reply.
I took some time to think this over.

R0J0hound wrote:The first thing is to detect the collision which is simple enough using the "is overlapping" condition.


Well to be honest the collision detection is not that simple in my situation I dont think (surely not for me).

I can detect for right and left no problem, by setting up a variable that switches depending on which arrow was pressed last.
But for the up and down movement its different, I have a different mechanic and cannot do so.
I am using self.Y+[other variables]*dt to define the movement, and it seems I cannot marry in the vector movements to be able to have the angle direction.


I was wondering if there is an easy way to check which side of the sprite was hit (or which side is overlapping), left, right, up, down (in another program I used this was already implemented in the system as events) and then perform and event/action accordingly. I have tried to use image points, but Im not sure how to handle the image points on the corners as they would be overlapped from 2 sides, and I really dont want to attach sensors all around manually, but will do so in the end if Im forced.

Additionally, I am using a formula for the speed, thus your example in which the system checks for the angle the player is moving is not appropriate for me.

Also I dont mean to spam, but Ive created another thread with a more elaborate question regarding my problem, and I would appreciate if you could check it out: viewtopic.php?f=147&t=165815
Brick by brick, stone by stone.
B
50
S
22
G
13
Posts: 273
Reputation: 10,413


Return to How do I....?

Who is online

Users browsing this forum: Aergo, anty21ro, Ethan, Fenix18, Iftikhar555 and 11 guests