Hello,
So I created some animations for a character who has a camera. But I made the animations with the camera. Now I can’t move the camera vertically. How can i resolve that problem please ?
Thank you in advance !
You’ll have to explain more.
What do you mean “Has a camera” Holding a camera model? Has a camera parented to him? Camera has keyframes?
No it’s the character parented to the camera.
Ok so is your camera controlled by a script? Something thats explicitly telling it to be at a certain height?
I am thinking by your first post, that it isn’t and that your camera has some keyframes on it, that are forcing it to move back to where you don’t want it… You want to probably remove then if so, on the camera object, or at least the y translation ones. Is it a first person setup, or a third person where you can see the back of your characters head?
The script is applying the character but it controls the camera and the character’s movement. And by the way, it’s a first person setup.
Anything in your script forcing your cameras y position?
Yes i think it’s that :
Vector3 desiredMove = cam.transform.forwardinput.y + cam.transform.rightinput.x;
You really need to post your whole script. Its a lot of guesswork for everyone else when we don’t know what the rest of your script is doing.
EG whats “input” and how are you calculating it? Post your script and we can provide better feedback.
- but it does look like the issue you are having stems from here.
It’s a script from a prefab in the “standard assets” so i don’t really know how it works… Anyway there’s the script.
Oh right. Yea the Unity guys love writing stuff that is not that easy to follow if you’re new or an artist.
Its an ugly place to start, for progress’s sake I’d try and get rid of all the camera code in this, make sure you cameras parented to your character object, and put a mouselook script on your camera for a start. The default samples are written by highend coders and its probably fair to say most of us never really get whats happening in detail with these examples. The authors don’t seem to understand this disconnect with their users, so yea, keep trying and don’t try to figure it all out anytime soon.
You could try beating it into submission with your keyboard or strangling it with your mouse cord;
Maybe:
desiredMove.y = desiredMove.y*movementSettings.CurrentTargetSpeed;
Could be assaulted into something like
desiredMove.y = desiredMove.y*movementSettings.CurrentTargetSpeed+(yourOffset);
eg
desiredMove.y = desiredMove.y*movementSettings.CurrentTargetSpeed+(1.5f);
EDIT: I just added and "f"to the 1.5^
Don’t know, guessing now. Its late and even if it was early I wouldn’t attempt deciphering this personally.
Try that else time for someone else to step in sorry.
I don’t know if this is any help- its the original RigidBodyFPS script in Javascript from 2006. Still a little complex but still easier to follow. It comes from a setup as I described where the camera is simply parented to the player capsule with a mouselook on it.
I apologise if its so old it just doesn’t work. It might be useful to you though.
var speed = 10.0;
var gravity = 10.0;
var maxVelocityChange = 10.0;
var canJump = true;
var jumpHeight = 2.0;
private var grounded = false;
@script RequireComponent(Rigidbody, CapsuleCollider)
function Awake ()
{
rigidbody.freezeRotation = true;
rigidbody.useGravity = false;
}
function FixedUpdate ()
{
if (grounded)
{
// Calculate how fast we should be moving
var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
targetVelocity = transform.TransformDirection(targetVelocity);
targetVelocity *= speed;
// Apply a force that attempts to reach our target velocity
var velocity = rigidbody.velocity;
var velocityChange = (targetVelocity - velocity);
velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
velocityChange.y = 0;
rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
// Jump
if (canJump && Input.GetButton("Jump"))
{
rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
}
}
// We apply gravity manually for more tuning control
rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));
grounded = false;
}
function OnCollisionStay ()
{
grounded = true;
}
function CalculateJumpVerticalSpeed ()
{
// From the jump height and gravity we deduce the upwards speed
// for the character to reach at the apex.
return Mathf.Sqrt(2 * jumpHeight * gravity);
}
Ok thanks for helping and i’ve another question : is it better to use animator or animation in my case to resolve the problem of the camera not moving ? Because if i turn off the animator attach to the character, the MouseLook works
Are you using an animator to animate hands on front of your camera?
If so you should have that as a child of your main object
The hierarcy is usually like
x-Root (Capsule Collider with rigidbody fps script - usually with mouselook that enables left to right rotation)
xx-(Camera usually with mouselook that enables up and down rotation)
xx-(Animated Hands as child of Capsule Collider-Which is where your animation/Animator should be located)
- My point being that the Camera Mouselook and Animator/Animation are usually down two forks of the hieracy, and you shouldn’t have any interference.
If you don’r have animated hands or a body viewd in first person, you shouldn’t need either animator or animation, because you are driving your movement via script. Its two layers really, and this tends to apply to NPCs and Player characters:
3dmovement in the worlds space: Controlled by script.
player/Npcs animations (walk jump etc): parented to scripted controller, triggered by script (or mecanim state machine), but keyframed artwork made in a modelling or animation app.
So if you do have animated keyframed artwork- its animator should be in the hireacy where its not effecting your mouselooks and camera and if you don’t have keyframed animated artwork I cant see why you’d need a animator or animation component and you can try removing it.