make object events wor if something else is nearby

Get help using Construct 2

Post » Tue May 01, 2012 12:09 pm

Hi,

I am building an adventure point and click game, in the game there will be a lot of objects for the player to interact with. What I want is for the object to only be clickable and useful when the player is near the object.

My initial idea was to create an invisible object that acts as an area of effect, so if the player is overlapping that radius object then the item becomes clickable... But that would require lots of extra objects being added to the layout.

As the game will have a lot of objects that the player can interact with is there a better way of doing this that doesnt require adding objects to the layout as I want to improve the games efficiency as much as possible.

Thanks.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056

Post » Tue May 01, 2012 2:52 pm

There are some situations where trigger objects are the way to go, but for what you describe you can use the distance expression to see if the player is within a certain distance of the other thing. Create a system event using the compare two values condition:

system-> distance(player.x,player.y,thing.x,thing.y)<=thing.reach

where reach is an instance variable created on the thing object(s) that contains how close to the thing the player has to be to reach it to interact with it.

At first I thought it would be better to put "reach" on the player, but you may have to be closer to some objects than others, so it would be better to have it on the thing.

If you have many different kinds of objects, and are using the paid version you can put all of your interactive objects in a family and create the "reach" instance variable on it. Otherwise you'll have to create the "reach" instance variable on each type of object you want the player to interact with in this way. But that is a lot better than having to create a bunch of trigger objects!

kittiewan2012-05-01 15:01:16
B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Tue May 01, 2012 3:06 pm

That is perfect thank you, I am using the paid so will probably use the families as you suggested. Thank you that should greatly improve the performance and be much easier to alter as needs be.
B
25
S
7
G
5
Posts: 185
Reputation: 5,056


Return to How do I....?

Who is online

Users browsing this forum: gregorysforster, heliogame, WhosWho and 15 guests