Right, me and a friend are starting a new project - a UFO game. our problem is the UFO he’s modelled (in “3ds max”) is zapping its position to 0.0.0 co-ordinates if its on auto-play animation.
also, i could really use a tutorial on model animations so i can get this looking cool can somebody point me in the right direction please?
I really wouldn’t use animation for movement… here, this is a script from a space game i’m developing, you’ll have to set up your inputs to use it…
It’s in javascript by the way…
Also, ignore the Max Speed percent thing unless you are setting an object to move forward on its own.
@script RequireComponent (Rigidbody)
// set turning speed variables.
var baseTurnSpeed:float=10;
var maxTurnSpeed:float = 20;
var maxSpeed:float = 200;
var maxSpeedPercent:int = 0;
static var warpAllowed:boolean = true;
static var doWarp:boolean = false;
static var speedBoost = 1;
//decide if a player will control this ship.
var playerControlled:boolean=true;
//is the pitch inverted?
var invertVertical:boolean=true;
function SetPlayerControl(control:boolean)
{
playerControlled = control;
}
function Update()
{
if (playerControlled)
{ //get new axis rotation buttons
pitched = Input.GetAxis("Vertical");
yaw = Input.GetAxis("Horizontal") ;
roll = Input.GetAxis("Roll");
//get speed setting.
if (Input.GetButtonDown("engine 0%"))
maxSpeedPercent = 0;
if (Input.GetButtonDown("engine 10%"))
maxSpeedPercent = 10;
if (Input.GetButtonDown("engine 20%"))
maxSpeedPercent = 20;
if (Input.GetButtonDown("engine 30%"))
maxSpeedPercent = 30;
if (Input.GetButtonDown("engine 40%"))
maxSpeedPercent = 40;
if (Input.GetButtonDown("engine 50%"))
maxSpeedPercent = 50;
if (Input.GetButtonDown("engine 60%"))
maxSpeedPercent = 60;
if (Input.GetButtonDown("engine 70%"))
maxSpeedPercent = 70;
if (Input.GetButtonDown("engine 80%"))
maxSpeedPercent = 80;
if (Input.GetButtonDown("engine 90%"))
maxSpeedPercent = 90;
if (Input.GetButtonDown("engine 100%"))
maxSpeedPercent = 100;
}
//vertical axis is default as inverted, so we will multiply by -1 to switch to none inverted if it's unchecked.
if(!invertVertical)
pitched *= -1;
//perform all rotation commands.
transform.Rotate(pitched * baseTurnSpeed * Time.deltaTime *10,yaw * baseTurnSpeed * Time.deltaTime *10,roll * baseTurnSpeed * Time.deltaTime *10);
rigidbody.velocity = transform.forward * Time.deltaTime * (maxSpeed * maxSpeedPercent * speedBoost) * 1;
if (Input.GetButtonDown("Warp"))
if (warpAllowed)
{
warpAllowed = false;
doWarp = true;
}
}
Mixamo created something they’re calling the “animation-driven character controller” for Unity which is supposed to update your character’s position to match the animation. I haven’t used it so I can’t speak for the quality of it, but it sounds like something which might help you.
ehm, thanks for the replies but i think you’ve misunderstood - im not telling the UFO to move, i havent scripted it or asked it to go anywhere. no matter where i put it in the editor, if the “Auto play animation” box is checked the UFO model just goes to this position and plays itself.
I cant see any reason for it doing this D: whats happening?! D:
Whenever this happens to me, I have the artist fix it in Maya. I’m pretty sure the problem is that the UFO’s animation is done in world space at the zero vector. I think he fixes it by adding an empty object as a parent to the model. I’m not sure if this is the optimal solution, but it has worked for us.
AaronC told you the reason in his first response, but if you want a more in depth explanation, here goes :
When you set the transform position of an object in Unity, you’re setting the position.
When you play an animation on an object, you’re setting the position over and over again to create the illusion of movement.
When you do both at the same time, they fight - you’ll set the position of the UFO, then the animation will set it back to where it expects it to be.
The fix is to never directly set the position an object that is being animated - attach the animated object to an empty gameObject (or add one in your modelling package like MegadethRocks suggests) and move the gameObject instead.
Interestingly enough this rarely happens with more complex characters because when Unity imports a hierarchy it creates an empty node at the base which is safe to reposition.