Help with your scripting

Collision?

Collision?

Postby ant0N » 15 Mar 2013, 03:07

Hi!
How it works the function onCollision_Start()?
I need a function that is called when the collision of an entity and returns them to the ID
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby SolarPortal » 15 Mar 2013, 11:56

there is a collision demo in the tech demos folder.

SkylineSDK\Asset Library\Scenes\Tech Demos\Collisions\Simple Collision Example

This demonstrates a bouncing ball that makes a sound on contact with the floor.
The Rigidbody attached to the ball entity contains a microscript with the onCollision_Start() event.

The collision function passes the hitID that was contacted with.
If you want to do something specific with a scene entity, place a catch and check if the hitID is the one your after.

You could get the name of the scene entity in the scene entity list by using "entity.getEntityName(hitID);"

Example:
Code: Select all
sound.setLooped( 0 );
sound.setVolume( 1 );
sound.setSoundFile( "bling.ogg" );
sound_ID = sound.create2DSound();

function onCollision_Start(hitID)
   sound.play2DSound( sound_ID );
   name = entity.getEntityName(hitID);
   sky.lprint("name: "..name);
end


In order to recieve onCollision_Start() callback, you must first check the "start touch" property on the rigidbody action under the Physics Collisions Header.
The same works for "on stay" and "end touch" events aswell.

Hope this Helps :D
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Collision?

Postby ant0N » 15 Mar 2013, 14:06

thank you SolarPortal, but it's not quite what I need...
I need a script entity1 receive id of all entity, with which he is faced. ;)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 15 Mar 2013, 14:16

Hey antON, if you can provide me an example of how you would like to use the feature and I will have a look at adding it for you ;)
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: Collision?

Postby ant0N » 15 Mar 2013, 16:09

thank you very much NightHawk!! :D :D
I suggest to do a command like this:
id = entity.collision(objID)
returns the ID of the entity with which the collision
like the getLastHitEntityID()

I am ready to discuss... ;)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 15 Mar 2013, 17:23

Ok ,the existing onCollision_Start(hitID) does what I think you are after ;)

The onCollision_Start(hitID) callback gets called when the entity with this script collides with any rigid body or any body collides with it. This is a common way of doing collisions in pro engines.

When a collision happens with this entity , the entity with the script has its onCollision_Start(hitID) called and the id of the colliding object is passed as the arg hitID.

Doing it this way is very performance friendly, fast and easy to manage, especially for large fast paced games.

Also you don't have to use the micro script on the rigid body the onCollision_Start event is available in the main script ( as long as the object the script is attached to has a rigid body action).

The event callback is better than doing this check in the main game loop ;)
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: Collision?

Postby ant0N » 15 Mar 2013, 17:32

thanks again! I will deal :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 15 Mar 2013, 17:36

If you get stuck we are here to help you ;)
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: Collision?

Postby ant0N » 16 Mar 2013, 15:07

first you need to watch the video to understand what it was about.
http://www.youtube.com/watch?v=cEJ8_yRxA9E&feature=youtu.be
I have two objects - ENTITY 1 and ENTITY 2.
object ENTITY 2 creates a new sphere every 2 seconds and sends them to the object of the ENTITY 1.
Object ENTITY 1 creates a larger sphere...
Question: how does the micro script object ENTITY 1 find out the ID of each small sphere in a collision?

PS. tried to do through triggers, through raycast and collision_start()... nothing happens :(
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 17 Mar 2013, 16:37

Thanks antON, I don't think there is a direct solution for what you are asking. This is due to the objects that are being spawned, the micro script does not see the new objects as it only reads events from the object that it is attached to.

But there is another way you can do this! ;)

All collisions require that the object has a rigid body. It is this rigid body that acts as the bounds for the collision. The onCollision() event is called by each of these objects as their bounds contact with another rigid body.

Each spawned object needs to have a rigid body. Next we need to spawn a lua script file with this new object. To use your example:

Entity 1: spawns sphere and then attaches a lua script to it. This script has to be a script file as there is currently no way to spawn a micro script. The script file for entity 1 contains the collision event so we can detect who has collided with it. Then each time this event is called check the arg hitID to see which object collided with it.

Hope this helps ;)
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: Collision?

Postby ant0N » 17 Mar 2013, 18:20

thanks for the help NightHawk!!! I realized that I need to do :)
I will write when I get to do it. :D
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 17 Mar 2013, 19:00

:D
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: Collision?

Postby ant0N » 19 Mar 2013, 11:18

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

Re: Collision?

Postby StarFire » 19 Mar 2013, 13:42

I will try to recreate your project, if possible can you send me a zip of your scene and any external script files.

I am sure, together we can get it to work ;)
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: Collision?

Postby ant0N » 20 Mar 2013, 09:05

here's my project. I will be very grateful for help. :D
http://yadi.sk/d/6P00KqSF3P3tE
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby SolarPortal » 20 Mar 2013, 14:26

after playing with your project, we believe there are a few commands you require that dont exist yet, which we will implement for the next release.

* physics.enableOnCollideStart(id, true); -- For enabling the onCollision_Start(hitID) event on the selected object.
* physics.enableOnColliding(id, true); -- For enabling the onCollision_Stay(hitID) event on the selected object.
* physics.enableOnCollideEnd(id, true); -- For enabling the onCollision_End(hitID) event on the selected object.

Note: In the scene settings panel, check the debug physics property to display physics meshes in the scene, then you will see the below comments meaning. :)

In your project scene, i noticed that you were moving the object using entity.move();
because it is a physics mesh you wish to move, you need to use the command physics.setVelocity(bID,0,0,10);
This will then move the entity with the physics mesh.

Another note: it is wise to grab the id of the physics body when you call physics.addBody(); e.g.

bID = physics.addBody(e.mesh,1,1)
physics.setVelocity(bID,0,0,10);

Physics properties work from the physics body ID.

Another noted problem: The large ball could not have the dynamic flag set to static when physics.addBody() is called.
This will be checked out aswell.

Thanks anton for helping improve the lua libraries. :D
User avatar
SolarPortal
Skyline Founder
Skyline Founder
 
Posts: 3631
Joined: 29 Jul 2012, 15:56
Location: UK
Skill: 3D Modeller
Skill: 2D Artist
Skill: Programmer
Skill: Level Designer

Re: Collision?

Postby ant0N » 20 Mar 2013, 16:05

SolarPortal wrote:
In your project scene, i noticed that you were moving the object using entity.move();
because it is a physics mesh you wish to move, you need to use the command physics.setVelocity(bID,0,0,10);
This will then move the entity with the physics mesh.


stupid mistake... :oops:

thank you, guys! I'll wait for the next release... :D
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby ant0N » 22 Mar 2013, 16:01

when will the next update? I can't wait to continue the work on their project.... :D
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby StarFire » 22 Mar 2013, 18:00

We hope to start the code freeze next week and try to get a release soon after ;)
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: Collision?

Postby StarFire » 29 Mar 2013, 16:40

Hi antON, we have fixed the collision system ready for your project. There were a few issues:

  • Spawned physics objects now callback to the spawned script on collision.
  • Spawned physics objects can now have their collision flag set in lua so they work in a similar way to the physics actions.
  • Spawned physics objects can now be either static or dynamic, this was broken in the current lua physics system

I have tested it with your project and it works fine now, these fixes will be in the new update for you ;)

New release update is now being prepred ;)
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: Collision?

Postby ant0N » 30 Mar 2013, 01:58

Hi, NightHawk! Thank you for helping me!!! :D :D
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby ant0N » 02 Apr 2013, 05:05

NightHawk wrote:
I have tested it with your project and it works fine now, these fixes will be in the new update for you ;)

New release update is now being prepred ;)


give me please your example. I have nothing happens. :?
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: Collision?

Postby ant0N » 02 Apr 2013, 05:53

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

Re: Collision?

Postby StarFire » 02 Apr 2013, 10:22

It looks like you are using the wrong flag, try using the command:

Code: Select all
physics.setCollisionEnable_OnStart(bodyID)


hope this helps ; )

PS I will upload your our working version of your project.
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: Collision?

Postby ant0N » 03 Apr 2013, 07:05

NightHawk wrote:
PS I will upload your our working version of your project.


thanks, I'll wait for your version. :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Next

Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 1 guest

cron