Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dyingIsMainstream
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gamejam-gpn15
dyingIsMainstream
Commits
4e779c8a
Commit
4e779c8a
authored
Jun 05, 2015
by
Philipp Adolf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change rotation of rockets
Interpolation is now done between the current and target rotation, so that the magnitude of the velocity is constant.
parent
83bf8ea8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
Rocket.cs
Assets/Scripts/Rocket.cs
+7
-6
No files found.
Assets/Scripts/Rocket.cs
View file @
4e779c8a
...
...
@@ -6,8 +6,8 @@ public class Rocket : MonoBehaviour
#
region
members
public
int
damagePoints
=
15
;
public
float
flyToTargetSpeed
=
10
f
;
public
float
speed
=
1
f
;
public
float
rotationSpeed
=
5
f
;
public
float
speed
=
5
f
;
public
float
pushForce
=
20f
;
//wie stark das target weggeschubst wird beim aufprall.
private
Rigidbody2D
body
;
...
...
@@ -26,10 +26,11 @@ public class Rocket : MonoBehaviour
if
(!
target
)
return
;
//update direction:
Vector3
direction
=
target
.
position
-
transform
.
position
;
body
.
velocity
=
Vector2
.
Lerp
(
body
.
velocity
,
(
float
)
speed
*
direction
.
normalized
,
Time
.
deltaTime
*
flyToTargetSpeed
);
Quaternion
newRotation
=
Quaternion
.
Euler
(
0
,
0
,
-
Mathf
.
Rad2Deg
*
Mathf
.
Atan2
(
direction
.
x
,
direction
.
y
));
transform
.
rotation
=
Quaternion
.
Slerp
(
transform
.
rotation
,
newRotation
,
Time
.
deltaTime
*
flyToTargetSpeed
);
Quaternion
targetRotation
=
Quaternion
.
FromToRotation
(
Vector2
.
up
,
target
.
position
-
transform
.
position
);
Quaternion
newRotation
=
Quaternion
.
Slerp
(
transform
.
rotation
,
targetRotation
,
Time
.
deltaTime
*
rotationSpeed
);
body
.
velocity
=
newRotation
*
(
speed
*
(
Vector2
.
up
));
transform
.
rotation
=
newRotation
;
}
void
OnTriggerEnter2D
(
Collider2D
other
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment