Difference between revisions of "FF7/Field/Script/Opcodes/C3 OFST"

From Final Fantasy Inside
< FF7‎ | Field‎ | Script‎ | Opcodes
Jump to navigation Jump to search
my_wiki>BukTop
m (2 revisions imported)
(Movement Types)
 
(4 intermediate revisions by 2 users not shown)
Line 25: Line 25:
 
* '''const Short''' ''Y'': Y offset amount, relative to current position, or address to find Y offset, if ''B2'' is non-zero.
 
* '''const Short''' ''Y'': Y offset amount, relative to current position, or address to find Y offset, if ''B2'' is non-zero.
 
* '''const Short''' ''Z'': Z offset amount, relative to current position, or address to find Z offset, if ''B3'' is non-zero.
 
* '''const Short''' ''Z'': Z offset amount, relative to current position, or address to find Z offset, if ''B3'' is non-zero.
* '''const UShort''' ''S'': Speed of the offset movement, if type is non-zero, or address to find speed, if ''B4'' is non-zero.
+
* '''const UShort''' ''S'': Step-count of the offset movement, if type is non-zero, or address to find speed, if ''B4'' is non-zero.
  
 
==== Description ====
 
==== Description ====
Line 33: Line 33:
 
If B1, B2, B3 or B4 is non-zero, then the value for that particular component is taken from memory using the corresponding bank and address specified, rather than as a literal value. Both retrieved values and literals can be used for different components. If using ''T'', ''X'', ''Y'' or ''S'' as addresses, the lower byte should hold the address whilst the higher byte should be zero.
 
If B1, B2, B3 or B4 is non-zero, then the value for that particular component is taken from memory using the corresponding bank and address specified, rather than as a literal value. Both retrieved values and literals can be used for different components. If using ''T'', ''X'', ''Y'' or ''S'' as addresses, the lower byte should hold the address whilst the higher byte should be zero.
  
The amount to offset is specified relative to the current position. If '''T'''ype is specified, the object moves gradually from its current point to the offset position; this can be used to simulate movements such as elevators. Any type outside the range in the table will cause the offset not to occur. If the object is set to move gradually, then the speed of offset can be set; the greater the number, the slower the object moves to its target offset.
+
The amount to offset is specified relative to the current position. If '''T'''ype is specified, the object moves gradually from its current point to the offset position; this can be used to simulate movements such as elevators. Any type outside the range in the table will cause the offset not to occur.
 +
 
 +
If the object is set to move gradually, then the number of steps to use to reach the destination can be set.  The current step is incremented by one as the movement progresses.  The ratio of the current step to total steps is used to determine the current progress through the movement, so the greater the number of steps, the slower the object moves toward its target offset.
 +
 
 +
In the case of linear movement, a simple linear interpolation is used :
 +
  current position = start position + total distance * current step / total steps.
 +
 
 +
In the case of smooth movement, a cosine function is used to simulate "ease-in" and "ease-out" of the perceived speed :
 +
  current position = start position + total distance * ((cos(π * current step / total steps + π) + 1) / 2)
 +
 
 +
For the sake of speed, the above calculations are done using look-up tables and fixed-point arithmetic.
  
 
Script execution may also be halted until the gradual offset has been completed. For this, see [[FF7/Field/Script/Opcodes/C4 OFSTW|OFSTW]].
 
Script execution may also be halted until the gradual offset has been completed. For this, see [[FF7/Field/Script/Opcodes/C4 OFSTW|OFSTW]].
Line 41: Line 51:
 
{| border="1" cellspacing="1" cellpadding="3" style="border: 1px solid black; border-collapse: collapse;"
 
{| border="1" cellspacing="1" cellpadding="3" style="border: 1px solid black; border-collapse: collapse;"
 
! style="background:rgb(204,204,204)" width="40" | ID
 
! style="background:rgb(204,204,204)" width="40" | ID
! style="background:rgb(204,204,204)" width="150" | Movement Type
+
! style="background:rgb(204,204,204)" width="170" | Movement Type
 
|-
 
|-
 
| align="center" | 0
 
| align="center" | 0
Line 47: Line 57:
 
|-
 
|-
 
| align="center" | 1
 
| align="center" | 1
| Linear (Point-to-point)
+
| Linear (No acceleration)
 
|-
 
|-
 
| align="center" | 2
 
| align="center" | 2
| Quadratic (Smoothed)
+
| Cosine (ease-in/ease-out)
 
|-
 
|-
 
|}
 
|}

Latest revision as of 13:08, 18 October 2022

  • Opcode: 0xC3
  • Short name: OFST
  • Long name: Offset Object

Memory layout

0xC3 B1 / B2 B3 / B4 T X Y Z S

Arguments

  • const Bit[4] B1: Bank to retrieve X offset, or zero if X is specified as a literal.
  • const Bit[4] B2: Bank to retrieve Y offset, or zero if Y is specified as a literal.
  • const Bit[4] B3: Bank to retrieve Z offset, or zero if Z is specified as a literal.
  • const Bit[4] B4: Bank to retrieve speed, or zero if S is specified as a literal.
  • const UByte T: Type of movement.
  • const Short X: X offset amount, relative to current position, or address to find X offset, if B1 is non-zero.
  • const Short Y: Y offset amount, relative to current position, or address to find Y offset, if B2 is non-zero.
  • const Short Z: Z offset amount, relative to current position, or address to find Z offset, if B3 is non-zero.
  • const UShort S: Step-count of the offset movement, if type is non-zero, or address to find speed, if B4 is non-zero.

Description

Offsets the field object, belonging to the entity whose script this opcode resides in, by a certain amount. After being offset, the character continues to be constrained in movement as defined by the walkmesh's shape, but at a certain distance away from the normal walkmesh position. Other field objects are unaffected, and their position or movements are maintained on the walkmesh's original position.

If B1, B2, B3 or B4 is non-zero, then the value for that particular component is taken from memory using the corresponding bank and address specified, rather than as a literal value. Both retrieved values and literals can be used for different components. If using T, X, Y or S as addresses, the lower byte should hold the address whilst the higher byte should be zero.

The amount to offset is specified relative to the current position. If Type is specified, the object moves gradually from its current point to the offset position; this can be used to simulate movements such as elevators. Any type outside the range in the table will cause the offset not to occur.

If the object is set to move gradually, then the number of steps to use to reach the destination can be set. The current step is incremented by one as the movement progresses. The ratio of the current step to total steps is used to determine the current progress through the movement, so the greater the number of steps, the slower the object moves toward its target offset.

In the case of linear movement, a simple linear interpolation is used :

  current position = start position + total distance * current step / total steps.

In the case of smooth movement, a cosine function is used to simulate "ease-in" and "ease-out" of the perceived speed :

  current position = start position + total distance * ((cos(π * current step / total steps + π) + 1) / 2)

For the sake of speed, the above calculations are done using look-up tables and fixed-point arithmetic.

Script execution may also be halted until the gradual offset has been completed. For this, see OFSTW.

Movement Types

ID Movement Type
0 Instantaneous
1 Linear (No acceleration)
2 Cosine (ease-in/ease-out)