Physics problem

Get help using Construct 2

Post » Sun Jul 15, 2012 10:52 pm

On mouse click I create a new instance of an object with physics enabled at mouse x and y. The object is a plank 125 by 25, and the initial instance is set horizontally at 0 angle. (collision mask set to bounding boxes)

The problem occurs when I want to spawn the same object at 270 vertically next to a wall. The created object gets pushed away as the initial instance was at 0 and only after its created changes to 270.

The event goes as following:

On Left button clicked
->Create object Plank
->Plank set angle to x degrees


Is there a way to overcome this problem?
B
33
S
12
G
7
Posts: 227
Reputation: 7,582

Post » Sun Jul 15, 2012 11:47 pm

Set up a boolean variable called "cursor distance", set it to True by default.

Set up a System event to run every tick, calling check on the distance between your cursor and the wall. If the value is less than 125, the action of this event will set "cursor distance" to false.

On your current event add the condition: Cursor distance=true

Change your current event to an If statement.

This is where I'm going to have to delve into even worse pseudocode, apologies, I'm a bit rushed atm :S

Set the Else to create your plank object at mouse.y+ the distance from wall (Call it from a variable updated every tick?)

Sorry, that went off badly and probably isn't much help! :(

There's also likely a much simpler solution using origin points or something! Sadly I'm new Mr E Bear2012-07-15 23:49:01
B
49
S
14
G
3
Posts: 540
Reputation: 5,611

Post » Mon Jul 16, 2012 11:16 am

Would this work:

Create plank at (-500, -500)
Plank set angle to 270 degrees
Plank set position to (mouse.x, mouse.y)
B
54
S
28
G
18
Posts: 1,520
Reputation: 24,990

Post » Mon Jul 16, 2012 2:06 pm

@ramones
I tried that but the plank would randomly spin when positioned to mouse x, y.

@Mr E Bear
I'm not sure if I understood, but that wouldn't solve much.


On the other hand, you gave me an idea.
What if I would keep that initial instance (usually I would have it destroyed) and rotate that as the player chooses the angle at which to spawn the new object. With that the initial object would be at the same angle as the spawned object would need to be.


UPDATE: apparently the current angle of the initial object doesn't matter, but the initial angle.
It would be really nice to have a "at angle" option in the Create object action.KFC2012-07-16 15:26:46
B
33
S
12
G
7
Posts: 227
Reputation: 7,582


Return to How do I....?

Who is online

Users browsing this forum: Timedoor Indones and 19 guests