Jump to content

[HELP] Projectile collision


Recommended Posts

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
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
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='[ &quot;false&quot; ]' />)?

But thanks anyway!

Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...