Page 1 of 1

Changing an object's location?

PostPosted: Sat Jun 25, 2011 4:56 am
by tachzusamm
I'm wondering if it's possible to change an object's location directly; if it's done with AlcScript or Python does not matter for now.

Assume the avatar clicks a button, now my object should change its location from A to B. Or to C. Or back to A.

I mean, I can imagine to do this with an animation (IPO curve), containing the possible locations, and triggering the anim accordingly. To set it to location A, one could call the animation to start at 1 sec. and end at 2 sec, to set location B, call with start 3 sec, stop with 4 sec. for example.

This should work, I guess, but before I start to write complex animation AlcScript with triggers, reponders, all that stuff, for each object I like to behave this way, I just wanted to ask if there's an easier way to change an object's location directly, without using animations.

The object does not need to "move", simply switching the location (maybe call it warping or beaming) would be fine.

And hints greatly appreciated :)

Re: Changing an object's location?

PostPosted: Sat Jun 25, 2011 6:24 am
by Sirius
The OfflineKI uses some kind of function like this...
I think it should be this:
Code: Select all
def WarpObjectToPos(object, x, y, z):
    pos = object.position()
    matrix = object.getLocalToWorld()
    matrix.translate(ptVector3(x-pos.getX(), y-pos.getY(), z-pos.getZ()))
    object.netForce(1)
    object.physics.warp(matrix)

Re: Changing an object's location?

PostPosted: Sat Jun 25, 2011 6:36 am
by tachzusamm
Hey, this looks pretty cool and short. :)
Thank you Sirius, I will give it a try.

Re: Changing an object's location?

PostPosted: Sat Jun 25, 2011 4:23 pm
by tachzusamm
Well, it seems I'm not familiar enough with Plasma itself.

I can pass an object's name via AlcScript to a Python script, but how to get the object itself from its name to pass it to the function?

Re: Changing an object's location?

PostPosted: Sun Jun 26, 2011 8:49 am
by Sirius
You can use PtFindSceneobject(objectname, agename) to get the object and it should then work with WarpObjectToPos. Don't forget to use ".value" to get the value of your string.
You should rather pass the object itself, I don't know how to do it with AlcScript, but in your PythonFileMod in the PRP, it should look like this:
Code: Select all
      <plPythonParameter ID="<id>" Type="SceneObjectList">
         <plKey Name="<scene object name>" Type="plSceneObject" Location="<location>" LocFlag="0x0000" />
      </plPythonParameter>

You can then re-use it in Python with this:
Code: Select all
<object variable> = ptAttribSceneobject(<integer for id>, '<description of the object>')

Re: Changing an object's location?

PostPosted: Sun Jun 26, 2011 9:43 pm
by tachzusamm
Thanks again; I already tried, but no luck currently with what I intended.
Well, no worries - seems I'm trying to overcomplicate something, I have to simplify it first.

But I stumbled accross this thread:
viewtopic.php?f=59&t=1499&p=15326&hilit=sceneobject#p15326
where D'Lanor already asked a similar question about how to pass a sceneobject to Python.

to be continued...


By the way, what does object.NetForce(1) in WarpObjectToPos do?
Tell other clients in a multiplayer environment that the object should be warped for them as well, in the next object.physics.warp(matrix) call?
And, if object.NetForce(1) is omitted, would this warp the object in the local client only (which would be great for what I intend)?

Re: Changing an object's location?

PostPosted: Mon Jun 27, 2011 1:05 am
by Sirius
tachzusamm wrote:By the way, what does object.NetForce(1) in WarpObjectToPos do?
Tell other clients in a multiplayer environment that the object should be warped for them as well, in the next object.physics.warp(matrix) call?
And, if object.NetForce(1) is omitted, would this warp the object in the local client only (which would be great for what I intend)?

I guess it is something like that. According to the Python API:
Code: Select all
Method: netForce(forceFlag) - Specify whether this object needs to use messages that are forced to the network;- This is to be used if your Python program is running on only one client;Such as a game master, only running on the client that owns a particular object;- Setting the netForce flag on a sceneobject will also set the netForce flag on;its draw, physics, avatar, particle objects

You can also use netForce(0). This should make sure the game doesn't broadcast it.

Re: Changing an object's location?

PostPosted: Mon Jun 27, 2011 7:51 am
by diafero
I'm not sure what the default for netForce is, so I always set it to 1 or 0, depending on what I want.

Re: Changing an object's location?

PostPosted: Mon Jun 27, 2011 8:21 am
by tachzusamm
Sirius wrote:You should rather pass the object itself, I don't know how to do it with AlcScript, ...
You can then re-use it in Python with this:
Code: Select all
<object variable> = ptAttribSceneobject(<integer for id>, '<description of the object>')

Hey, thanks again - I got it working this way.

Some notes, just for completion:
As for the AlcScript, the parameters had to be type: sceneobject, and with ref: scnobj:<BlenderObjectName>, like this:
Code: Select all
        actions:
          - type: pythonfile
            name: WarpObjectPythonFileMod
            pythonfile:
                file: paraWarpObject
                parameters:
                  - type: activator
                    ref: logicmod:logicMod_WarpEnter
                  - type: activator
                    ref: logicmod:logicMod_WarpExit
                  - type: sceneobject
                    ref: scnobj:ObjectToWarp

(I attached the warping to a region to trigger its execution)

In the Python file:
...
warpOb = ptAttribSceneobject(2)
...
later in the class:
pos = warpOb.position() # <== this did not work, but
pos = warpOb.sceneobject.position() # <== this did!

And, the object had to be an Actor (otherwise "object has no coordinate system" was given as an error in the log).

diafero wrote:I'm not sure what the default for netForce is, so I always set it to 1 or 0, depending on what I want.

I will keep this in mind. :)


EDIT: The "warping objects" project continued here:
viewtopic.php?f=59&t=5254