Commit c9bb8362 authored by kgingras's avatar kgingras
Browse files

camera and movement fixed. need gravity fix

parent b724bec4
......@@ -10,18 +10,19 @@ public class CapsuleController : MonoBehaviour {
public Vector3 myForward = Vector3.zero;
public Vector3 myRight = Vector3.zero;
float moveSpeed = 6; // move speed
float turnSpeed = 90; // turning speed (degrees/second)
float lerpSpeed = 10; // smoothing speed
bool isGrounded;
public bool isGrounded;
float deltaGround = 0.2f; // character is grounded up to this distance
float jumpSpeed = 10; // vertical jump initial speed
public float jumpSpeed = 10; // vertical jump initial speed
float jumpRange = 10; // range to detect target wall
float yRot;
private Vector3 surfaceNormal; // current surface normal
private Vector3 myNormal; // character normal
public Vector3 myNormal; // character normal
private float distGround; // distance from character position to ground
private bool jumping = false; // flag "I'm jumping to wall"
private float vertSpeed = 0; // vertical jump current speed
......@@ -29,6 +30,8 @@ public class CapsuleController : MonoBehaviour {
Vector3 moving = Vector3.zero;
Rigidbody rb;
ThirdPersonAnimator thirdPersonScript;
// Use this for initialization
void Start () {
myNormal = transform.up; // normal starts as character up direction
......@@ -36,7 +39,7 @@ public class CapsuleController : MonoBehaviour {
distGround = transform.position.y - 0f;
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true; // disable physics rotation
thirdPersonScript = gameObject.GetComponent<ThirdPersonAnimator> ();
}
// Update is called once per frame
......@@ -45,12 +48,14 @@ public class CapsuleController : MonoBehaviour {
Ray ray;
RaycastHit hit;
if (Input.GetButtonDown("Jump")){ // jump pressed:
if (Physics.Raycast(transform.position, -myNormal, out hit, jumpRange)){ // wall ahead?
// JumpToWall(hit.point, hit.normal); // yes: jump to the wall
}
else if (isGrounded){ // no: if grounded, jump up
rb.velocity += jumpSpeed * myNormal;
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");
rb.AddForce(jumpSpeed * myNormal);
}
}
......@@ -66,17 +71,16 @@ public class CapsuleController : MonoBehaviour {
}
myNormal = Vector3.Lerp(myNormal, surfaceNormal, lerpSpeed*Time.deltaTime);
Debug.Log (myNormal + " normal normal" + myNormal.normalized);
GetMouseLook();
GetMovement();
AddGravity();
}
void Update(){
if (isGrounded) {
AddGravity ();
} else {
AddRealGravity();
}
GetMouseLook();
}
void GetMovement(){
......@@ -99,47 +103,32 @@ public class CapsuleController : MonoBehaviour {
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);
}
void AddGravity(){
rb.AddForce(-gravityForce*myNormal);
}
void AddRealGravity(){
rb.AddForce(-gravityForce*Vector3.up);
}
void GetMouseLook(){
//
float yRot = Input.GetAxis("Mouse X") * sensitivity;
float xRot = Input.GetAxis("Mouse Y") * sensitivity;
yRot = Input.GetAxis("Mouse X") * sensitivity;
transform.rotation *= Quaternion.Euler (0f, yRot, 0f);
// m_CameraTargetRot *= Quaternion.Euler (-xRot, 0f, 0f);
//
// if(clampVerticalRotation)
// m_CameraTargetRot = ClampRotationAroundXAxis (m_CameraTargetRot);
//
// if(smooth)
// {
// character.localRotation = Quaternion.Slerp (character.localRotation, m_CharacterTargetRot,
// smoothTime * Time.deltaTime);
// camera.localRotation = Quaternion.Slerp (camera.localRotation, m_CameraTargetRot,
// smoothTime * Time.deltaTime);
// }
// else
// {
// character.localRotation = m_CharacterTargetRot;
// camera.localRotation = m_CameraTargetRot;
// }
}
void OnCollisionStay(Collision collision){
foreach (ContactPoint contact in collision.contacts) {
Debug.DrawLine(contact.point, contact.point + contact.normal, Color.green, 2, false);
isGrounded = true;
}
}
......
fileFormatVersion: 2
guid: d5a2c54474161204ca5a9c474a949062
folderAsset: yes
timeCreated: 1454553420
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ea2a5216ffb8d4b319d09e8d7782120c
folderAsset: yes
guid: 434a23743c3897740a48dcfa6c785919
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: c0403fc643172c24d982b950222fa77d
folderAsset: yes
timeCreated: 1454553420
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 928a1af7a9ed6404c91809ed5bb1bfb7
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: -1
maxTextureSize: 1024
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:
fileFormatVersion: 2
guid: 453c24430a661514eac833dfdde4b26a
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: -1
maxTextureSize: 1024
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:
fileFormatVersion: 2
guid: 85eb5edd982b0464a8f943d62aa4d5d8
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: -1
maxTextureSize: 1024
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:
fileFormatVersion: 2
guid: 07376177150371d439b6412c7604af68
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: -1
maxTextureSize: 1024
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:
fileFormatVersion: 2
guid: 33b0feabc2e03fa48958b8b6f7bc96e0
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Military_Rifle_Free
A Subset of “Military_Rifle”
Check out the video here:
http://youtu.be/2ktqkSzp0ko
6 Military Rifle Animations; featuring a set of AAA game-ready military style motions with a rifle.
Includes a relaxed idle, a walk, walking aim, jog aim, crouch idle and standing fidget.
All animations are .fbx format, standard fbx bone names.
Locomotions are included as traveling motions.
M4_Rifle_01 - A matching fully textured Rifle has been included as a separate asset .fbx file. Parenting or constraining it with zero offset to the “RH_WP” bone in the right hand will place and animate it correctly. It has been parented into the hierarchy in the default setup scene.
UNITY 3D NOTES:
The “Default_Setup” scene has the Rifle (or Pistol) parented to the “RH_WP” bone in the Hierarchy with zero offset. (See image 01) All animations have been simply added to the Animator, so any motion you right-click - “Set as Default” will play/preview in the Scene viewport with the weapon in hand.
The “Default_Setup” has been included as a convenience to initially view/preview the motions with the weapon. The Scene, Controller, and Hierarchy can be altered or deleted as you see fit for your use.
“MotusMan_v2” is the main Avatar and currently set to “Generic”. All Animation files have been set to use its Avatar. After initially opening the scene, files in the “Animation” folder will likely not be visible in the Preview viewport. (See images 02, 03) Dragging “MotusMan_v2” into the Preview will make them visible. The weapon will not be visible in the Preview, only in the Scene viewport. (See above description) Specifically looping animations have been set to “Loop”.
Of course, all parameters can be altered and set up to implement the animations as you wish. If the Rig is set to “Humanoid”, all “Muscle” assignments should automatically be correct, except for “Chest”. “MotusMan_v2” has three spine bones, and the third, “Spine2”, is likely the better choice versus the auto-choice “Spine1”.
Please refer to the Unity documentation or contact us with any other questions.
mocap@motusdigital.com
ANIMATION LIST
MIL2_M3_W1_Stand_Relaxed_Idle
MIL2_M3_W1_Walk_F_Loop
MIL2_M3_W1_Walk_Aim_F_Loop
MIL2_M3_W1_Jog_Aim_F_Loop
MIL2_M3_W1_Crouch_Idle
MIL2_M3_W1_Stand_Relaxed_Fgt_v1
Provided Motus Man character is copyright © Motus Digital, LLC
fileFormatVersion: 2
guid: 095536c75856c3e43b0ddc411e2a2d13
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 0a41e39944a1c0943b5706a6b537a879
folderAsset: yes
timeCreated: 1454553420
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f8d68aa084aa36a49ae6799e957c86c2
folderAsset: yes
timeCreated: 1454553420
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment