Home
Documentation
Change Log
Videos
Downloads
Forums
Get It!
Account
Register (temporarily disabled)
Login // Logout
Edit Profile
Translate To Snap ActionClip
Slate Forums
›
Custom Clips
›
Translate To Snap ActionClip
This topic has 0 replies, 1 voice, and was last updated
7 years, 5 months ago
by
itsallgoodgames
.
Viewing 1 post (of 1 total)
Author
Posts
November 27, 2017 at 09:23
#1365
itsallgoodgames
Participant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using
UnityEngine
;
using
Slate
;
using
Slate
.
ActionClips
;
[
Category
(
"Transform"
)
]
[
Description
(
"IMPORTANT stepRate <= length \n RECOMMENDED length/stepRate = whole number \n 5sec/1rate = 5 steps + 1 = 6"
)
]
public
class
TranslateToSnap
:
ActorActionClip
{
[
SerializeField
]
[
HideInInspector
]
private
float
_length
=
1
;
public
Vector3
targetPosition
;
[
Min
(
0
)
]
public
float
stepRate
=
1f
;
private
Vector3
originalPos
;
public
override
string
info
{
get
{
return
string
.
Format
(
"Translate To Snap\n{0}"
,
targetPosition
)
;
}
}
public
override
float
length
{
get
{
return
_length
;
}
set
{
_length
=
value
;
}
}
public
override
float
blendIn
{
get
{
return
length
;
}
}
protected
override
void
OnEnter
(
)
{
originalPos
=
actor
.
transform
.
position
;
}
protected
override
void
OnUpdate
(
float
deltaTime
)
{
int
steps
=
(
int
)
(
length
/
stepRate
)
;
Vector3
stepLength
=
(
targetPosition
-
originalPos
)
/
(
steps
+
1
)
;
int
currentStep
=
(
int
)
(
(
deltaTime
*
(
steps
)
)
/
(
length
)
)
;
Vector3
pos
=
originalPos
+
(
stepLength
*
(
currentStep
+
1
)
)
;
if
(
length
==
0
)
{
actor
.
transform
.
position
=
targetPosition
;
return
;
}
actor
.
transform
.
position
=
pos
;
}
protected
override
void
OnReverse
(
)
{
actor
.
transform
.
position
=
originalPos
;
}
#if UNITY_EDITOR
protected
override
void
OnSceneGUI
(
)
{
DoVectorPositionHandle
(
TransformSpace
.
WorldSpace
,
ref
targetPosition
)
;
}
#endif
}
Author
Posts
Viewing 1 post (of 1 total)
You must be logged in to reply to this topic.
Log In
Username:
Password:
Keep me signed in
Log In