Please or Register to create posts and topics.

Synchronizing objects on an axis:

Page 1 of 2Next

I am trying to cause two objects two have the same height (in this example) and the code I am trying so far is:

Code: Select all
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

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.

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,

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:

Code: Select all
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)

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

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:

Code: Select all
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!

Sorry I didn't see there was a new post I'm looking into it now.

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:

Code: Select all
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.

Image

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.

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

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.

Page 1 of 2Next