Aw mover rider change
Minimum requirements | ||
---|---|---|
Added in version 4.1 | ||
SDK | build 53 |
int aw_mover_rider_change (int id, int session, int dist, int angle, int y_delta, int yaw_delta, int pitch_delta)
Description
Changes how a rider is attached to a mover.
Callback
None (returns immediately)
Notes
If the method is succesful then it will trigger an AW_EVENT_ENTITY_RIDER_CHANGE event.
Arguments
- id
- Mover ID. Reference to AW_ENTITY_ID.
- session
- Session number of the rider.
- dist
- Distance in the XZ plane from the origo of the mover object to the rider.
- angle
- Angle in the XZ plane between the Z axis of the mover object and the rider.
- y_delta
- Distance along the Y axis from the origo of the mover to the Y coordinate of the rider.
- yaw_delta
- Yaw of the rider, relative to the yaw of the mover object.
- pitch_delta
- Pitch of the rider, relative to the pitch of the mover object.
Argument attributes
None
Return values
- RC_SUCCESS
- RC_NOT_INITIALIZED
- RC_NO_INSTANCE
- RC_NO_CONNECTION
- The connection to the world is down.
- RC_UNAUTHORIZED
- Only instances owned by a caretaker (i.e. aw_bool (AW_WORLD_CARETAKER_CAPABILITY) returns 1) may use this method.
Returned attributes
None
Usage
See Movers for an example how to change states and thereby control a mover.
To calculate a rider's position relative to a mover:
#define PI ((double)3.1415926535897932f) float dx = sin (PI / 180.0f * (m_CurrentYaw + rider_Angle)) * rider_Dist; float dz = cos (PI / 180.0f * (m_CurrentYaw + rider_Angle)) * rider_Dist; float dy = rider_DeltaY; float dyaw = m_CurrentYaw + rider_DeltaYaw; float dpitch = m_CurrentPitch + rider_DeltaPitch;
The resulting variables dx, dz, dy as well dyaw and dpitch define the location of a rider relative to the mover.
Note, the m_Current* variables define the mover's current position and rotation. The rider_* variables used are represented as float data type in meters or degrees.
Consequently, the reverse calculation, as it can be used before adding a rider or changing a rider's position, looks like:
#define RADIANS_TO_DEGREES 57.29577951f wanted distance in X axis: float dx = avatar_x - m_Current.x; wanted distance in Z axis: float dz = avatar_z - m_Current.z; int distance = (int)(sqrt (dx * dx + dz * dz) * 1000); int angle = ((atan2 (dx, dz) * RADIANS_TO_DEGREES) - m_CurrentYaw) * 10; int deltaY = (int)(avatar_y * 1000) - (int)(m_Current.y * 1000); int deltaYaw = (int)(avatar_yaw * 10) - (int)(m_CurrentYaw * 10); int deltaPitch = (int)(avatar_pitch * 10) - (int)(m_CurrentPitch * 10);
The resulting integer values can be used as parameters in aw_mover_rider_add or aw_mover_rider_change.
Note, the m_Current* variables define the mover's current position and rotation. The avatar_* variables used are represented as float data type in meters or degrees.
A mover's intermediate position can be calculated like:
float delta = (float)(aw_tick () - m_LastChange) / aw_int(AW_WORLD_AVATAR_REFRESH_RATE); m_Current.x = delta * (m_Pos.x - m_LastPos.x) + m_LastPos.x; m_Current.y = delta * (m_Pos.y - m_LastPos.y) + m_LastPos.y; m_Current.z = delta * (m_Pos.z - m_LastPos.z) + m_LastPos.z; m_CurrentYaw = delta * (m_Yaw - m_LastYaw) + m_LastYaw; m_CurrentPitch = delta * (m_Pitch - m_LastPitch) + m_LastPitch; m_CurrentRoll = delta * (m_Roll - m_LastRoll) + m_LastRoll;
Note, this is assuming the m_LastChange is set to aw_tick when the mover position was sent or receiver the last time, depending if the bot is the controlling instance of the mover or not. The according position and rotation values in m_Last* variables are alse set at that time. All examples here use float for position or rotation coordinates, unless specified different.
A bot should avoid to interpolate intermediate positions. It is recommended to use the aw_mover_rider_add functions only when the mover is NOT in AW_MOVER_STATE_MOVE state. It is also recommended to issue a call to aw_mover_rider_change ONLY right after the mover was set to AW_MOVER_STATE_MOVE as shown in the Movers example.