Custom movement against solid

Get help using Construct 2

Post » Sat Nov 19, 2011 5:38 pm

Dear all,

I'm trying to learn to use C2 without the use of behaviours (am I on a hiding to nothing here?) and am trying to get one sprite to interact with another - as much as a player object would against a solid.

The only way I can think of doing this is to check the collision status after the key press and coord update, but before these changes are submitted to the screen ...and cancelling the change if there is a collision.

I'm just darned if I know how to do this in C2.

Any pointers much appreciated.

Noob.
B
5
G
2
Posts: 17
Reputation: 1,266

Post » Sat Nov 19, 2011 8:23 pm

Why not use behaviours?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sat Nov 19, 2011 9:13 pm

Here is a basic way to do it:

Every Tick:
+ Sprite: set X to: Sprite.X + 1

Sprite: is overlapping Wall:
+ Sprite: set X to: Sprite.X - 1


If the motion is more complex another way to do it would be to save the sprite's x,y position in variables before moving the sprite. Then if it collides with a wall you can undo the motion by setting the sprite's position to the values in the variables.
B
79
S
24
G
53
Posts: 4,735
Reputation: 40,233

Post » Sun Nov 20, 2011 6:21 am

I'd personally put another, invisible sprite behind the main one, making it slightly (depending on the speed of the game) larger than the main one. Then use that to tell your collision, in the sense that if the right-hand side of the object is colliding with a wall, ignore the invalid input.

There are several ways to do this, but I'd recommend behaviors.
B
14
S
1
G
2
Posts: 85
Reputation: 2,810


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], R0J0hound and 25 guests