Changing an object's location?

If you feel like you're up to the challenge of building your own Ages in Blender or 3ds Max, this is the place for you!

Changing an object's location?

Postby tachzusamm » Sat Jun 25, 2011 4:56 am

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 :)
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Changing an object's location?

Postby Sirius » Sat Jun 25, 2011 6:24 am

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)
User avatar
Sirius
 
Posts: 1508
Joined: Mon Jul 26, 2010 4:46 am
Location: France

Re: Changing an object's location?

Postby tachzusamm » Sat Jun 25, 2011 6:36 am

Hey, this looks pretty cool and short. :)
Thank you Sirius, I will give it a try.
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Changing an object's location?

Postby tachzusamm » Sat Jun 25, 2011 4:23 pm

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?
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Changing an object's location?

Postby Sirius » Sun Jun 26, 2011 8:49 am

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>')
User avatar
Sirius
 
Posts: 1508
Joined: Mon Jul 26, 2010 4:46 am
Location: France

Re: Changing an object's location?

Postby tachzusamm » Sun Jun 26, 2011 9:43 pm

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)?
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany

Re: Changing an object's location?

Postby Sirius » Mon Jun 27, 2011 1:05 am

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.
User avatar
Sirius
 
Posts: 1508
Joined: Mon Jul 26, 2010 4:46 am
Location: France

Re: Changing an object's location?

Postby diafero » Mon Jun 27, 2011 7:51 am

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 prefer e-mails to "diafero arcor de" (after adding the at and the dot) over PMs.

"Many people's horizon is a circle with a radius of zero. They call it their point of view."

Deep Island Shard | Offline KI
diafero
Deep Island Admin
 
Posts: 2972
Joined: Mon May 05, 2008 5:50 am
Location: Germany

Re: Changing an object's location?

Postby tachzusamm » Mon Jun 27, 2011 8:21 am

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
User avatar
tachzusamm
 
Posts: 575
Joined: Thu May 29, 2008 2:03 am
Location: Germany


Return to Building

Who is online

Users browsing this forum: No registered users and 1 guest