Help with your scripting

How to check the collision between 2 Objects

How to check the collision between 2 Objects

Postby StarFire » 10 Nov 2012, 12:04

How to check for collisions between the two objects? -Copied from antOns Post: viewtopic.php?f=14&t=48&start=25#p209

how to check for collisions between objects?
Code: Select all
if EntityCollided(Entity1, Entity2) then
    --...
end
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: How to check the collision between 2 Objects

Postby StarFire » 10 Nov 2012, 12:13

At the moment collisions are an area that has not been developed far, as we have concentrated on the editor side of development. There is a basic cursor ray-cast to world but no entity to entity version. I will start looking into various methods of collision and post the results here ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Как проверить столкновения между 2 Объектов

Postby ant0N » 10 Nov 2012, 12:36

OK! I look forward to
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Как проверить столкновения между 2 Объектов

Postby ant0N » 10 Nov 2012, 15:07

consider this scenario:
function Collision(Entity, force, speed)

end

This function is called each time when the subject is confronted with something.
The Entity if the Entity = 0, then in a collision with any object will be called by this function.
force - the force at which is called by this function. If force = 0, then any power.
speed - the speed at which this function is called. If speed = 0, then any speed.
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: How to check the collision between 2 Objects

Postby StarFire » 16 Nov 2012, 15:08

We have been busy working on some basic collision tools. The first has been passed to lua and I have been testing it on a simple space invader style project. The bullet checks to see if it has hit an object.

entity.isColliding(objID,directionX,directionY,directionZ,range) this is a polly precise collision ray cast from the object in the direction specified. The range is the collision range.

There is also a partner command to check to see what the last object hit was.

entity.getLastHitEntityID() returns the ID of the object hit by the collision ray.

The following code snippet is from the bullet script:

Code: Select all
function onUpdate( timeDelta )
   x,y,z = entity.getPosition( obj );
   entity.move(obj,0,moveSpeed*timeDelta,0);
   particle.setParticlePosition( fxid,x, y, z  );
   if(y > height) then
      delete();
   else
      if(entity.isColliding(obj,0,1,0,2)>0) then
         entity.delete(entity.getLastHitEntityID());
         delete();
      end
   end
end


These commands will be in the next patch update in the next week ; )
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Как проверить столкновения между 2 Объектов

Postby ant0N » 16 Nov 2012, 15:28

Well finally I wait for a reply :) . Still don't really understand how it works...
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: How to check the collision between 2 Objects

Postby StarFire » 16 Nov 2012, 15:52

the bullet checks to see if it has hit an object which is in range by the statement:

Code: Select all
if(entity.isColliding(obj,0,1,0,2)>0) then...


once there has been a collision the isColliding() returns the value 1 for a hit.

then you can get the object that has been hit by calling the getLastHitEntityID() command which returns the hit objects ID. In the case of the bullet it deletes the object that it collided with.

Code: Select all
entity.delete(entity.getLastHitEntityID());


Maybe I will make the invader demo into a tutorial if that would help ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer

Re: Как проверить столкновения между 2 Объектов

Postby ant0N » 16 Nov 2012, 16:18

Yes, please!
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: How to check the collision between 2 Objects

Postby StarFire » 16 Nov 2012, 16:53

Ok, when I get some time I will write this up as a tutorial , added to our to-do list ;)
User avatar
StarFire
Skyline Founder
Skyline Founder
 
Posts: 1678
Joined: 03 Jan 2012, 18:50
Location: UK
Skill: Great creative
Skill: Programmer
Skill: 3D Modeller
Skill: 2D Artist
Skill: Level Designer


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 7 guests

cron