need help: projectileCollider that blocks only one spell

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
Illidan
Posts: 19
Joined: Sat Mar 12, 2016 3:23 pm
Location: Germany

need help: projectileCollider that blocks only one spell

Post by Illidan »

I have a door that is open and I attached a wall_trigger to it, so the opened door can still act as a projectileCollider when I fire a spell to close the door.
The problem is, such a projectileCollider act as all or nothing. So all projectiles like spells and items do collide.
Is there a way to only let a specific spell collide with the wall_trigger (for example a close_door spell)? All other spells and items shall pass normaly through the opened door!

A conclusion could help me with a similiar problem:
I want to throw daggers, rocks and darts and shoot arrows through closed portcullis. All other items and spells shall be blocked normally.

Can anyone help?
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: need help: projectileCollider that blocks only one spell

Post by minmay »

Use the collisionMask and collisionGroup properties of ProjectileComponent and ProjectileColliderComponent, respectively. For example, a collision mask of 0 will only collide with solid tiles, and pass through all ProjectileColliderComponents. A ProjectileColliderComponent with a collision group of 2 will only affect projectiles that also have that bit in their collision mask - so a collision mask of 2, 3, 6, 7, etc. would collide with it, but a collision mask of 1 (the default), 4, or 5 would not.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Illidan
Posts: 19
Joined: Sat Mar 12, 2016 3:23 pm
Location: Germany

Re: need help: projectileCollider that blocks only one spell

Post by Illidan »

Thank you minmay, I think this is a really good hint!
But I am still new to modding :oops: so could you please give me a more specific example how to use collisionMask and collisionGroup?

This is my door trigger:

defineObject{
name = "door_trigger",
components = {
{
class = "WallTrigger",
},
{
class = "ProjectileCollider",
size = vec(2.5, 3, 0.5),
--debugDraw = true,
},
},
placement = "wall",
editorIcon = 72,
}

How must I implement collisionGroup in here?

And the ProjectileComponent, is that the spell I have to modify with the collisionMask? And when yes, how? :roll:
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: need help: projectileCollider that blocks only one spell

Post by minmay »

Look at spells/dispel.lua and spells/runes.lua in the asset pack. They show how to use collisionMask and collisionGroup.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
Illidan
Posts: 19
Joined: Sat Mar 12, 2016 3:23 pm
Location: Germany

Re: need help: projectileCollider that blocks only one spell

Post by Illidan »

Thanx a lot, you are great minmay, that has helped!
I did not know, that an example of how to use collisionMask and collisionGroup already existed in the asset pack. :oops:
But I am still a noob and have much to learn. ;)
I have modified my open_door spell and my door trigger and now items and other spells than my open_door spell do no longer collide with the projectileCollider, as intended.
Though I still have to experiment a little bit with the group and mask numbers. :)
sleepy
Posts: 15
Joined: Wed Feb 04, 2015 2:34 am

Re: need help: projectileCollider that blocks only one spell

Post by sleepy »

So, I've been trying something similar. Making a custom monster that does not collide with projectiles, and does collide with the party. I haven't got it fully worked out yet; I need to make them collide with the party yet. I got them to not collide with projectiles by setting:

Code: Select all

class = "monster" 
swarm = true, 
If you add this to it:

Code: Select all

{
	class = "ProjectileCollider",
	collisionGroup = 1,
},
Then the monster will collide with projectiles but not the party. This is effectively the opposite of what I want, but I'm taking it as forward progress.

The issue is: doors, monsters, walls, and the party are all implicitly projectileColliders. So I think what the trick is, in a general sense, is to instead make a custom object out of a different base class, and then script in everything it does have for that instance. This makes the modifications needed to the rest of what's going on much lighter, as you don't have that implicit component to deal with. Though this isn't enough.

I'm not certain yet how the swarm(bool) gets around this, but I assume it's either calling a different object type that is a forked base_monster without the implicit collider, or somehow removing it. Interestingly enough, the mosquito_swarm isn't actually a swarm. I think only the rat_swarm is. So, on the other end of the issue I'm now trying to figure out how you can make something collide with the party.

Obstacles are the only reference I could find with: ObstacleComponent:setBlockParty(boolean)

So, what you could do for you door is make a custom Obstacle with the portcullis mesh and blockParty(true), repelProjectiles(false), give it a collision group, then place that in an archway and give your items the corresponding collision mask. Then, when the trigger activates: destroy the obstacle object, and spawn the portcullis Door on top of the Obstacle, and set it open.
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: need help: projectileCollider that blocks only one spell

Post by minmay »

It's heartening to see more people willing to experiment. To make a monster that doesn't collide with projectiles, and does collide with the party and get hit by melee attacks and TileDamagers, add this to the MonsterComponent definition:

Code: Select all

collisionRadius = 0,
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
sleepy
Posts: 15
Joined: Wed Feb 04, 2015 2:34 am

Re: need help: projectileCollider that blocks only one spell

Post by sleepy »

minmay wrote:It's heartening to see more people willing to experiment. To make a monster that doesn't collide with projectiles, and does collide with the party and get hit by melee attacks and TileDamagers, add this to the MonsterComponent definition:

Code: Select all

collisionRadius = 0,
Figures. That was one of very few components I never tried. I looked at a bunch of times thinking it was for party collision.

Thanks much.
Post Reply