Help with your scripting

physical object move for the target

physical object move for the target

Postby ant0N » 01 Nov 2013, 08:35

maybe a stupid question, but I couldn't find a solution.
How to make a physical object move for the target? Something like entity.lookatObject.
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: physical object move for the target

Postby SolarPortal » 01 Nov 2013, 09:21

great to hear from you anton :D

this sounds like you need a kinematic body, as normal dynamic objects will fight against the rotations and static are well static lol.
Have you got an example situation for use, e.g. a door opening...
> Maybe a test scene would help :P

NightHawk will see if its possible to implement a kinematic rigid body for the next release.

thank you for pointing this out, as it improves skyline every time :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: physical object move for the target

Postby ant0N » 01 Nov 2013, 09:32

Thank you! :lol: I just started to do the old project, and I need to my sphere, followed target. (such as a bullet). I think you will understand what I want. :D :D
http://yadi.sk/d/qiO_uizGBwifS
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: physical object move for the target

Postby SolarPortal » 01 Nov 2013, 12:22

ah i think i see. :P
You want the sphere that is spawned and rolling; to go towards the utility scale that spawns the trigger, wherever it is placed.

This you could then turn into a bullet, e.g. a large turret shot etc..
This might be possible by changing the linearvelocity or angularvelocity of the physics body.

We shall see what we can do :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: physical object move for the target

Postby SolarPortal » 01 Nov 2013, 12:29

just had a quick look:

is this the fix.
Add this onto ENTITY2 microscript in the update loop section, just before setting velocity, get the direction:

Code: Select all
speedMulti = 0.1;
dirX, dirY, dirZ = entity.subtractPositions( entity.getEntityIDFromTag("enemy"), entity.getEntityIDFromTag("tower") );


see larger snippet:
Code: Select all
   function e:update()
      if( entity.entityExist(self.mesh) == 1 ) then
         --entity.move(self.mesh,0,0,0.05)
         
         speedMulti = 0.1;
         dirX, dirY, dirZ = entity.subtractPositions( entity.getEntityIDFromTag("enemy"), entity.getEntityIDFromTag("tower") );
         physics.setVelocity(bID,-dirX * speedMulti, -dirY * speedMulti, -dirZ * speedMulti);
         if self.life < os.clock() then
            entity.delete(self.mesh)
         end   

      end
   end


Then save your microscipt.
I hope this helps and is what you needed. :D
if not then we can retry.

Edit: If you run in "animate mode" and move "ENTITY1", you will notice that the ball rolls and changes direction, which is quite cool :P
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: физический объект двигаться к цели

Postby ant0N » 01 Nov 2013, 13:10

Thanks for the help! Not quite what I need, but the principle, I realized. :D
I need to tiny sphere followed a large sphere. :)
Image
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: physical object move for the target

Postby ant0N » 01 Nov 2013, 13:30

another issue appeared.
IU need to remove the little sphere in a collision with a large sphere.
Code: Select all
   function e:update()
      if( entity.entityExist(self.mesh) == 1 ) then
         if self.target~= nil then
            if( entity.entityExist(self.target) == 1 ) then
               self.dirX, self.dirY, self.dirZ = entity.subtractPositions( obj, e.target );
               speedMulti = 1;
               physics.setVelocity(bID,-self.dirX * speedMulti, -self.dirY * speedMulti, -self.dirZ * speedMulti);
            end
         end
         
         --***********FUNCTION?***********************
         if COLLISION(self.mesh,self.target) then
            entity.delete(self.mesh)
         end
         
         if self.life < os.clock() then
            entity.delete(self.mesh)
         end   
      end
   end
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: physical object move for the target

Postby SolarPortal » 02 Nov 2013, 19:56

I need to tiny sphere followed a large sphere. :)

is what you need:
  • the small sphere being attached to the moving large sphere, and follows wherever it moves
or
  • moving seperate with a changing distance between the small sphere and large sphere.

e.g. if the large sphere stops, does the small sphere stop or carry on moving?
but all using physics bodies.

As for the collisions, are you not wanting the little sphere to collide with the large sphere, or is this something different.

We will get you up and running with the code you require :P
Each little bit improves skyline :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: физический объект двигаться к цели

Postby ant0N » 05 Nov 2013, 10:41

Я надеюсь, что это видео поможет вам понять, чего я хочу.
http://youtu.be/MKd3U69Ri_k
Image
когда маленькая сфера соприкасается с большой сферой, она должна быть удалена. :)
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller

Re: physical object move for the target

Postby SolarPortal » 05 Nov 2013, 11:38

the reason collision is not working is because you need to add a collision event flag:
Code: Select all
physics.setCollisionEnable_OnStart(bodyID);

after you have created the body.

example:
Code: Select all
function newEntity2()
   mesh2 = entity.spawn("Sphere_small",0,10,0,1,1,1);
   
   bid2 = physics.addBody(mesh2, enum.body_Sphere(), 1);
   physics.setCollisionEnable_OnStart(bid2);
   
   entity.addScript( mesh2, "/Jayce/testCollision.lua" );
   sky.lprint("new entity 2");
end


for the collision script attached (EDITED):
Code: Select all
obj = 0;

function onInit(objID)
   sky.lprint("LUA: Script Active!");
   obj = objID;
end

function onCollision_Start(hitID)
   sky.lprint("collision happened: deleting small sphere");
   entity.delete(obj);
end



then do your deletion inside the collisionevent.
If you add the collision event to the bullet, then it will all be self contained.

as it happens, we had missed this off the API list, whoops lol :P

there are also a collision stay and collsion end event.

Code: Select all
physics.setCollisionEnable_OnStay(bodyID);
physics.setCollisionEnable_OnEnd(bodyID);


hope this helps :D

Edit: API now updated
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: physical object move for the target

Postby SolarPortal » 05 Nov 2013, 14:02

We now have a tech demo displaying the use of collisions on spawned entities.
This will be in the next release.

Thanks for testing :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: physical object move for the target

Postby ant0N » 05 Nov 2013, 14:06

Thanks for the help! now I can move on... :D
User avatar
ant0N
Skyline Moderator
Skyline Moderator
 
Posts: 415
Joined: 02 Nov 2012, 12:49
Location: Россия, Москва
Skill: Programmer
Skill: 3D Modeller


Return to Lua Scripting

Who is online

Users browsing this forum: No registered users and 10 guests

cron