pbradjan1994 Posted July 22, 2019 Share Posted July 22, 2019 How can I set the projectile (id 19 - rocket) to not collide with the buildings, ground...? I have a shooter minigame, the car shoots rockets, and I want the rockets to only collide with another cars (hit the cars), which functions do I need to use? Link to comment
HassoN Posted July 22, 2019 Share Posted July 22, 2019 Make it not collidable with objects using setElementCollidableWith Second option could be: setElementCollisionsEnabled -- disable collision with everything setElementCollidableWith -- enable it with vehicles But I'm not sure about the last method. Link to comment
pbradjan1994 Posted July 22, 2019 Author Share Posted July 22, 2019 15 minutes ago, HassoN said: Make it not collidable with objects using setElementCollidableWith Second option could be: setElementCollisionsEnabled -- disable collision with everything setElementCollidableWith -- enable it with vehicles But I'm not sure about the last method. I tried something like this, but it is not working. Can you tell me where I am wrong? function projectileGhost ( ) local projType = getProjectileType( source ) if projType == 19 then local objects = getElementsByType("object") setElementCollidableWith(projType, objects, false) end end addEventHandler( "onClientProjectileCreation", getRootElement(), projectileGhost ) Link to comment
HassoN Posted July 22, 2019 Share Posted July 22, 2019 Just now, pbradjan1994 said: I tried something like this, but it is not working. Can you tell me where I am wrong? function projectileGhost ( ) local projType = getProjectileType( source ) if projType == 19 then local objects = getElementsByType("object") setElementCollidableWith(projType, objects, false) end end addEventHandler( "onClientProjectileCreation", getRootElement(), projectileGhost ) the 2nd argument of setElementCoollidableWith is an element not a table! use something like this instead: local objects = getElementsByType("object") for i, v in ipairs(objects) do setElementCollidableWith(source, v, false) -- i replaced projType with source because projType is a number while source is the element. end Link to comment
pbradjan1994 Posted July 22, 2019 Author Share Posted July 22, 2019 22 minutes ago, HassoN said: the 2nd argument of setElementCoollidableWith is an element not a table! use something like this instead: local objects = getElementsByType("object") for i, v in ipairs(objects) do setElementCollidableWith(source, v, false) -- i replaced projType with source because projType is a number while source is the element. end Unfortunately, it's not working, I tried to put your code inside and also outsideof the "if" statement, , but nothing happens. I need the part with the if statement, because I am changing the projectile velocity and counter, and that is working perfectly. I just can't figure out how to disable collisions. Does it matter if the collisions for the map are set ENABLED, I mean in meta.xml (<setting name="#ghostmode" value='[ "false" ]' />)? But thanks anyway! Link to comment
pbradjan1994 Posted July 23, 2019 Author Share Posted July 23, 2019 On 22/07/2019 at 12:26, HassoN said: the 2nd argument of setElementCoollidableWith is an element not a table! use something like this instead: local objects = getElementsByType("object") for i, v in ipairs(objects) do setElementCollidableWith(source, v, false) -- i replaced projType with source because projType is a number while source is the element. end Can you help me with this code: local objects = getElementsByType("object") for i, v in ipairs(objects) do setElementCollisionsEnabled(v, false) end This code works, it disables collisions with all objects, including rockets, so rockets go through walls, ground, buildings... But so does the player's car, so I tried to enable the collisions for vehicles only, after this code, but it doesn't work. I also tried to write a better code, to disable collisions just for projectiles, like this: local projectiles = getElementsByType("projectile") for i, v in ipairs(projectiles) do setElementCollisionsEnabled(v, false) end But nothing happens, I don't know why, so I was hoping that maybe you or anyone else can help me figure it out? Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now