Synchronizing objects on an axis:

Avatar
Soundlogic
169 Posts
Posted Jul 13, 2011
I am trying to cause two objects two have the same height (in this example) and the code I am trying so far is:

objtarget:SetAbsOrigin(Vector((objtarget:GetAbsOrigin()).x,(objtarget:GetAbsOrigin()).y,(objinfo:GetAbsOrigin()).z))

But it isn't working. I'm not sure about getting the components from the vector, and if AbsOrigin is what I want. If I can get this working I can probably get the geomatry go work on any axis, but I don't want to do that since it will make the code more complicated until I have the base code working. Any Advice?
Thank You,
Sound Logic

Advertisement
Registered users don’t see ads! Register now!
Avatar
Kasc
77 Posts
Posted Jul 13, 2011
Replied 16 minutes later
Looks like you're trying to do everything in one line which isn't a great idea if you're not able to do what you want to do.

Try setting variables for the x, y, z coordinates and printing to make sure you are getting the x, y and z values correctly.

P.S. I know nothing of squirrel, just rudimentary and general scripting knowledge.

Avatar
Soundlogic
169 Posts
Posted Jul 13, 2011
Replied 4 minutes later
I'm trying to stick to one line so I don't have to add a .nut file and can just use the run script code function, but when I make it more complicated I will probably at least temporarily turn it into a full script file,
Avatar
Omnicoder
299 Posts
Posted Jul 13, 2011
Replied 16 minutes later
You can't use RunScriptCode to run a line like that, you have to pass a function that exists in the script specified by the entity's Entity Scripts keyvalue.

Also, you can't treat an entity's name as a class/object.

The following is untested and I just wrote this in the post editor but it might work:

function ChangeY(target, source) {
 objectone = Entities.GetEntityByName(null,target);
 objecttwo = Entities.GetEntityByName(null,source);
 oone_origin = objectone.GetOrigin();
 otwo_origin = objecttwo.GetOrigin();
 objectone.SetOrigin(Vector(oone_origin.x, otwo_origin.y, oone_origin.z));
}

(it had some sloppy mistakes see below for fixed version)

Avatar
Soundlogic
169 Posts
Posted Jul 13, 2011
Replied 1 hour later
So I have a timer have that as one of its scripts, and then on timer I use (I changed the name to OverrideZ)
RunScriptCode:OverrideZ(Obj1,Obj2)?
Is this right?
Because it doesn't seem to be working, and I'm not sure if it is the script or my implementation of it.
Thank You,
Sound Logic
Avatar
Soundlogic
169 Posts
Posted Jul 14, 2011
Replied 1 day later
Help? Is the code right, and/or am I implementing it wrong?
Thank You,
Sound Logic

EDIT:
I looked into some of the code examples, and think I might have fixed some problems:

function OverrideZ(target, source) {
objectone <- Entities.FindByName(null,target);
objecttwo <- Entities.FindByName(null,source);
oone_origin <- objectone:GetOrigin();
otwo_origin <- objecttwo:GetOrigin();
objectone.SetOrigin(Vector(oone_origin.X, oone_origin.Y, otwo_origin.Z));
}

Not quite sure though
Thanks Omnicoder!

Avatar
Omnicoder
299 Posts
Posted Jul 14, 2011
Replied 10 minutes later
Sorry I didn't see there was a new post I'm looking into it now.
Avatar
Omnicoder
299 Posts
Posted Jul 14, 2011
Replied 2 hours later
Double posting only so he sees this since I fixed it.

My original code was sloppy and untested so I made sure it works this time:

function ChangeZ() {
   local objectone = Entities.FindByName(null,"obj2");
   local objecttwo = Entities.FindByName(null,"obj1");
   local oone_origin = objectone.GetOrigin();
   local otwo_origin = objecttwo.GetOrigin();
   objectone.SetOrigin(Vector(oone_origin.x, oone_origin.y, otwo_origin.z));
   objectone.SetVelocity( Vector( Max(objectone.GetVelocity().x-1, 0), Max(objectone.GetVelocity().y-1, 0), objectone.GetVelocity().z) );
}

function Max(a,b) {
   return (a == b) ? a : ((a > b) ? a : b);
}

It should be set as a script think function and you'll need to change the obj1 and obj2 strings if you want it to affect different objects.

img

It gets into odd spins sometimes, you can force set its angles or be stricter about its velocity if its a problem.

And btw <- is only for globals use = for locals in functions.

Avatar
Soundlogic
169 Posts
Posted Jul 14, 2011
Replied 39 minutes later
Sweet. You are incredible omnicoder. Love your work (please release more of it!). Twomore questions though: I'm looking on the list of vscript functions, and I'm not seeing any trig functions, which I kind of need to extend this to an arbitrary axis; and is it possible to make it receive the names of the objects, since I have read that using " in parameters causes problems, but I would prefer not to hardcode the object names.
Thank You So Much,
Sound Logic
Avatar
Omnicoder
299 Posts
Posted Jul 15, 2011
Replied 8 hours later
I was basing what I wrote off the pseudo-code you wrote in the first post, so I just made it to operate on X Y or Z. If you want it to work on an arbitrary axis you'll have to elaborate because the only changes on an arbitrary axis I'm familiar with are rotations. And you're correct that you can't pass strings. The only alternative to hardcoded object names I can think of would be to keep the object names in other entities as a parent so that GetParent can retrieve them but that simply indirects it one level.
Avatar
Soundlogic
169 Posts
Posted Jul 15, 2011
Replied 3 hours later
Would it work to store the entities in a global variable attached to a numerical id? Is there a way to have a script that saves the name of the object calling it in a variable on a table at a position specified? So I could have each of the objects call a script with a id number, and then that id number tells the controller script both of the entities? And about the trig thing, I'm not seeing things like sin/cos, which means I don't know how to make the effect along an arbitrary axis (currently x,y and z can be done, but not a axis that is a combination of those)
Thank You,
Sound Logic
Advertisement
Registered users don’t see ads! Register now!
Avatar
Omnicoder
299 Posts
Posted Jul 15, 2011
Replied 3 hours later
If you're OK with it being static in the map you can specify the entities in Entity Groups for the logic_script. If it has to be dynamic you'll need to pass numbers as parameters and append them to the name of a base or use them as an index into an array. As for the axis, you can aready do XY or YZ or XZ by changing which entity it reads origin from for which axes.