*** Screen point to Camera point
* You need to interprete the screen coordinate to world coordinate
* Camera has the ability to convert the screen coordinate to world coordinate
Example:
Camera cam;
Vector3 pointInWorldCoordinate = cam.ScreenPointToRay(Vector3 point)
*** Character Controlling, Moving
* care in mind that there are Local coordinate system and World coordinate system
* if you want to go forward in local coordinate, you should convert it to world coordinate system
* there are methods such as Transform.TransformDirection.
** refer to: World of Warcraft project
*** Navigation System
* NavMeshSurface
* NavMeshModifier
* NavMeshModifierVolume
* NavMeshLink
* NavMeshObstacle
* We can set Agent type.. meaning that each agent has its own path
* Using Modifier, we can adjust each game object in detail. ( has options like Ignore build, override ..)
* ModifierVolume is a component that affects baking.
* Use NavMeshObstacle when you want to calculate the path dynacally ( meaning being able to determine the path right before moving)
* NavMeshSurface has a method "BuildNavMesh", which we can use in code to build NavMesh on the fly.
* Basic Code snipet:
if (Input.GetMouseButtonDown(0))
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit))
{
agent.SetDestination(hit.point);
}
}
*** Animation System
Two basic concept
* Animation
* Avatar
* Animation has information of how to animate the skeleton (rig)
* Avatar has a skeleton (rig) - and optionally skins
* If you have an animation and two or more avatar, the avatars can animate on the animation,
so as a result all the avatars shows same motions based on the animation
- This is called Retargetting. (see below)
* Workflow
* prepare animations ( walk, run, jump)
* prepare animator controllers ( how to operate the animations)
* prepare avatars ( something that has similar bone structure that can match with animations)
* make animator using animation controllers and avatars prepared.
** See: Character Animation Setup in unity tutorial and local folder on your computer
** One of the most powerful features of Mecanim is retargeting of humanoid animations
** Retargeting is only possible for humanoid models, where an Avatar has been configured
*** Vector3.Reflect
Description
Reflects a vector off the plane defined by a normal.
The inNormal
vector defines a plane (a plane's normal is the vector that is perpendicular to its surface). the inDirection
vector is treated as a directional arrow coming in to the plane. The returned value is a vector of equal magnitude to inDirection
but with its direction reflected.
Reflection of a vector off a plane.
* If you want your character to be level with ground, use Cross Product of Normal vector and the character's right vector
* this gives us forward vector
*** Quaternion Operation
Quaternion1 * Quaternion2 <- 일종의 덧셈, Quaternion1에 Quaternion2를 더한 방향값이 나온다.
Example:
float turn = m_TurnInputValue * m_TurnSpeed * Time.deltaTime;
// Make this into a rotation in the y axis.
Quaternion turnRotation = Quaternion.Euler(0f, turn, 0f);
// Apply this rotation to the rigidbody's rotation.
m_Rigidbody.MoveRotation(m_Rigidbody.rotation * turnRotation);
'Projects > Unity' 카테고리의 다른 글
Understanding Unity 3D coordinate systems (0) | 2019.01.30 |
---|