Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
kgingras
ZeroGravGuy
Commits
05882b84
Commit
05882b84
authored
Feb 06, 2016
by
kgingras
Browse files
smoother Character Controller
parent
949595de
Changes
55
Show whitespace changes
Inline
Side-by-side
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_front.jpg.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: 4aa19d95d8173e847800d660d21da970
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_left.jpg
0 → 100644
View file @
05882b84
2.07 MB
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_left.jpg.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: efcf604c3a25bf940b9644440b847e8f
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_right.jpg
0 → 100644
View file @
05882b84
1.27 MB
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_right.jpg.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: 942a24a67e4303f41b6f89fcc0e02456
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_top.jpg
0 → 100644
View file @
05882b84
1.49 MB
Assets/Plugins/3Skyboxes/Skybox_GreenNebular_Textures/GreenNebular_top.jpg.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: 85f7e8a396aa40545a6748bc184a7a58
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -3
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 50
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: -1
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Assets/Scripts/CapsuleController.cs
View file @
05882b84
...
...
@@ -50,27 +50,24 @@ public class CapsuleController : MonoBehaviour {
Ray
ray
;
RaycastHit
hit
;
// if (Input.GetKeyUp(KeyCode.B)){ // jump pressed:
//
//// if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
//// // JumpToWall(hit.point, hit.normal); // yes: jump to the wall
//// }
// if (isGrounded){ // no: if grounded, jump up
// Debug.Log("jump");
// isGrounded = false;
////
//// Vector3 velocity = rb.velocity;
////
//// velocity += jumpSpeed * myNormal;
// rb.AddForce(jumpSpeed * myNormal, ForceMode.Impulse);
//
// }
// }
RaycastHit
forwardHit
;
if
(
Physics
.
Raycast
(
transform
.
position
,
-
myNormal
,
out
hit
,
Mathf
.
Infinity
)){
// use it to update myNormal and isGrounded
if
(
Physics
.
Raycast
(
transform
.
position
,
myForward
,
out
forwardHit
,
1f
)){
if
(
forwardHit
.
distance
<
hit
.
distance
){
isGrounded
=
forwardHit
.
distance
<=
distGround
+
deltaGround
;
surfaceNormal
=
forwardHit
.
normal
;
}
else
{
isGrounded
=
hit
.
distance
<=
distGround
+
deltaGround
;
surfaceNormal
=
hit
.
normal
;
}
}
else
{
isGrounded
=
hit
.
distance
<=
distGround
+
deltaGround
;
surfaceNormal
=
hit
.
normal
;
// thirdPersonScript.newNormal = surfaceNormal;
}
}
else
{
isGrounded
=
false
;
...
...
@@ -81,85 +78,73 @@ public class CapsuleController : MonoBehaviour {
myNormal
=
Vector3
.
Lerp
(
myNormal
,
surfaceNormal
,
lerpSpeed
*
Time
.
deltaTime
);
}
else
{
myNormal
=
Vector3
.
Lerp
(
myNormal
,
Vector3
.
up
,
lerpSpeed
*
Time
.
deltaTime
);
}
//adjust the rotation of the character based on the normal.
Quaternion
targetRot
=
Quaternion
.
LookRotation
(
myForward
,
myNormal
);
transform
.
rotation
=
Quaternion
.
Lerp
(
transform
.
rotation
,
targetRot
,
lerpSpeed
*
Time
.
deltaTime
);
GetMouseLook
();
GetMovement
();
// if (isGrounded) {
// AddGravity ();
// } else {
// AddRealGravity();
// }
}
void
GetMovement
(){
if
(
Input
.
GetKeyUp
(
KeyCode
.
B
)){
// jump pressed:
// if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
// // JumpToWall(hit.point, hit.normal); // yes: jump to the wall
// }
if
(
Input
.
GetKeyUp
(
KeyCode
.
Space
)){
// jump pressed:
if
(
isGrounded
){
// no: if grounded, jump up
Debug
.
Log
(
"jump"
);
isGrounded
=
false
;
//
// Vector3 velocity = rb.velocity;
//
// velocity += jumpSpeed * myNormal;
transform
.
position
+=
myNormal
*.
05f
;
rb
.
AddForce
(
jumpSpeed
*
myNormal
,
ForceMode
.
Impulse
);
}
return
;
}
float
h
=
Input
.
GetAxis
(
"Horizontal"
);
float
v
=
Input
.
GetAxis
(
"Vertical"
);
Vector3
targetVelocity
=
Vector3
.
zero
;
Vector3
velocity
=
Vector3
.
zero
;
Vector3
velocityChange
=
Vector3
.
zero
;
if
(
isGrounded
){
//forward and right adjusted based on the normal of the surface
myForward
=
Vector3
.
Cross
(
transform
.
right
,
myNormal
);
myRight
=
Vector3
.
Cross
(-
transform
.
forward
,
myNormal
);
//adjust the rotation of the character based on the normal.
Quaternion
targetRot
=
Quaternion
.
LookRotation
(
myForward
,
myNormal
);
transform
.
rotation
=
Quaternion
.
Lerp
(
transform
.
rotation
,
targetRot
,
lerpSpeed
*
Time
.
deltaTime
);
Vector3
targetVelocity
=
myForward
*
v
+
myRight
*
h
;
///add gravity here
// if (isGrounded) {
// targetVelocity += -gravityForce*myNormal;
// }
targetVelocity
=
myForward
*
v
+
myRight
*
h
;
targetVelocity
*=
walkSpeed
;
if
(!
isGrounded
)
{
targetVelocity
+=
-
gravityForce
*
Vector3
.
up
;
}
else
{
if
(
h
==
0
&&
v
==
0
){
}
else
{
targetVelocity
+=
-
runGravityForce
*
myNormal
;
}
velocity
=
rb
.
velocity
;
velocityChange
=
(
targetVelocity
-
velocity
);
rb
.
AddForce
(
velocityChange
,
ForceMode
.
VelocityChange
);
}
else
{
myForward
=
Vector3
.
Cross
(
transform
.
right
,
myNormal
);
myRight
=
Vector3
.
Cross
(-
transform
.
forward
,
myNormal
);
targetVelocity
=
myForward
*
v
+
myRight
*
h
;
targetVelocity
*=
(
walkSpeed
/
2
);
targetVelocity
.
y
-=
gravityForce
*
Time
.
deltaTime
;
rb
.
velocity
+=
targetVelocity
;
}
Vector3
velocity
=
rb
.
velocity
;
Vector3
velocityChange
=
(
targetVelocity
-
velocity
);
rb
.
AddForce
(
velocityChange
,
ForceMode
.
VelocityChange
);
//call thirdperson move
// Debug.Log (v + " vel:" +rb.velocity.magnitude + " change: " + velocityChange + " target: " + targetVelocity.magnitude);
thirdPersonScript
.
Move
(
targetVelocity
,
false
,
false
,
yRot
);
thirdPersonScript
.
Move
(
targetVelocity
,
false
,
!
isGrounded
,
yRot
);
}
void
AddGravity
(){
...
...
Assets/Scripts/ThirdPersonAnimator.cs
View file @
05882b84
...
...
@@ -33,13 +33,13 @@ public class ThirdPersonAnimator : MonoBehaviour {
m_Animator
=
GetComponent
<
Animator
>();
CCscript
=
GameObject
.
Find
(
"Capsule"
).
GetComponent
<
CapsuleController
>();
//
m_Rigidbody = GetComponent<Rigidbody>();
//
m_Capsule = GetComponent<CapsuleCollider>();
//
m_CapsuleHeight = m_Capsule.height;
//
m_CapsuleCenter = m_Capsule.center;
m_Rigidbody
=
GetComponent
<
Rigidbody
>();
m_Capsule
=
GetComponent
<
CapsuleCollider
>();
m_CapsuleHeight
=
m_Capsule
.
height
;
m_CapsuleCenter
=
m_Capsule
.
center
;
//m_Rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;
//
m_OrigGroundCheckDistance = m_GroundCheckDistance;
m_OrigGroundCheckDistance
=
m_GroundCheckDistance
;
}
// Update is called once per frame
...
...
@@ -106,4 +106,6 @@ public class ThirdPersonAnimator : MonoBehaviour {
m_Animator
.
speed
=
1
;
}
}
}
Assets/_scene_0.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: f035c724f5cf8c347b4ce85e2f8cc94d
folderAsset: yes
timeCreated: 1454808404
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Assets/_scene_0.unity
View file @
05882b84
No preview for this file type
Assets/_scene_0/LightmapSnapshot.asset
0 → 100644
View file @
05882b84
File added
Assets/_scene_0/LightmapSnapshot.asset.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: 6cdacfda6cb5297428d7df22a96a244d
timeCreated: 1454808404
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
Assets/_scene_0/ReflectionProbe-0.exr
0 → 100644
View file @
05882b84
File added
Assets/_scene_0/ReflectionProbe-0.exr.meta
0 → 100644
View file @
05882b84
fileFormatVersion: 2
guid: 3c7e6af9b719b8a4a85054a7f5754c1b
timeCreated: 1454808404
licenseType: Free
TextureImporter:
fileIDToRecycleName:
8900000: generatedCubemap
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 1
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 1
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: 2
aniso: 0
mipBias: 0
wrapMode: 1
nPOTScale: 1
lightmap: 0
rGBM: 0
compressionQuality: 100
allowsAlphaSplitting: 0
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 0
textureType: 3
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
Prev
1
2
3
Next
Write
Preview
Supports
Markdown
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