Simple question - entity orientation

#1
Hi,

does anyone know how to get an entity's orientation from LUA so that same vector can be later used in a spawn params table?

I have already tried with GetAngles() and GetDirectionVector() but they are obviously meant for different usages and thus not give the result I wish to get. I think I could somewhat calculate the orientation from their return values in some way but I have no clue as to how to do that.

Example

Code: Select all

local MyObject = System.SpawnEntity({ class = "SomeClass", name = "ImAnObject", orientation = {x = dirx, y = diry, z = dirz}, position = {x = posx, y = posy, z = posz}, etc... etc... }); ...some other code after which I have to get the entity's orientation at runtime local MyObjectOrientation = ???;
Suggestions are openly welcome :D

Re: Simple question - entity orientation

#6
Hi.
For getting the rotation, GetAngles is the right function. But due to a bug, it seems to have problems with values over 90 degree (1/2 * Pi rad).

GetAngles takes a table as a parameter and passes the rotation values into it.

So the following code should work fine:

Code: Select all

local direction = {x=0, y=0, z=0}; GetAngles(direction);
I have not tested the code above, so please forgive me if it doesn't work. I'll look into it tomorrow and test it.

I just hope, that CryTek will provide some sort of LUA integration for backward compatibility in future engine versions.

- Jannis

Re: Simple question - entity orientation

#7
Hi and thanks for your suggestion, but I'm not actually looking for the entity's rotation. What I'm after is orientation. There's a subtle difference between the two of them: from what I can get, orientation is "how much you are aligned to the X/Y/Z vector".

If you try to spawn an entity without specifying an orientation, it has {x = 0, y = 1, z = 0} by default, so it is apparently facing the positive Y axis irrespective of the actual geometry shape. Same goes with an entity placed somewhere with the Sandbox Editor without any rotation applied.

This is just wild guessing made through observation, that's why I was seeking some advice from the veterans here :D

Re: Simple question - entity orientation

#8
Hi joseph,
I'm not sure *exactly* what you want, but I'm guessing you want to set the angles etc of a spawned entity.
There's probably no reason to get the initial angles as the entity will always have the default angles (its y axis pointing along the Sandbox y axis).
I routinely spawn vehicle entities in my simulator, and also set their positions, angles and any other parameters as needed.
I only use the table to specify the entity class, partly as I'm not familiar with the specification of the entity table (it may not be documented).
.
After spawning it's easy to set parameters for the entity as the function returns the entity ID (MyObject in your example).
So, to set the engles and parameters of a spawned vehicle, I do something like this (pos and angles are set as required):

Code: Select all

local params = {}; params.class="Spitfire"; ID = System.SpawnEntity(params); ID:SetPos(pos); ID:SetAngles(angles); ID.Properties.Stuff = MoreStuff.......etc etc
Hope this helps,
Chris

Re: Simple question - entity orientation

#9
Everyone probably just raised an eyebrow while reading my first post and thought "Why don't you just use entity:SetAngles()"?

The thing is, my request is related to a very particular need of mine: I'm working on an add-on of sorts for the Crysis Wars community where changing the entity angles after being spawned is simply not as viable as it seems (clients to not receive the updated rotation, leading to situations where the result can range from "not acceptable" to "what is this thing").

So even though I posted it as a general question, I actually had a very peculiar scenario at hand that may or may not be solved with methods that "just work" in SP. After some trial and error it is clear that the orientation parameter translates to certain combinations of rotations around different axes but not all of them.

RMI / serialization is normally needed in MP for what I'm trying to accomplish AFAIK.
Thanks for your answer cwright and good luck with your simulator!

Re: Simple question - entity orientation

#10
Hi joseph,
Thanks!
One thought occurred. I only use SP, so that method works fine. Presumably it should work by setting the orientation parameters in the table.
But do you know the specific format required? I don't think I ever found documentation on the table.
Cry Engine probably has three methods for setting angles:
Explicit angles, vectors and a third method that uses 4 numbers, not three (I forget the name of this method, but in the past I actually wrote some code to convert from this to more useful angles).
Could it be that the table needs four numbers to set the angles, and not three?
Just a thought.
Regards,
Chris

Who is online

Users browsing this forum: No registered users and 4 guests

cron