Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

question to developers of e.g platform games

Discussion in 'Scripting' started by dacloo, Feb 1, 2006.

  1. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Hi!

    In Unity you can go the "transform" or "rigidbody" way. For platform game character movement, would you choose the former or the latter?
    My guts say that transform allows for a more arcadish feel, but if the same can be done with rigidbody, you get all the benefits of the physics engine in Unity.

    EDIT: I've set the drag of my rigidbody to 2, with a greater speed in movement, and now it feels much more arcadish, however, I don't want the drag to be applied for the Y (gravity) since gravity's too slow. I also dont want to adjust a global gravity parameters, because other objects might have drag 0 (and fall down very quickly). Is it possible to ignore the drag Y ?

    http://otee.dk/Documentation/ScriptReference/CharacterController.html
    What does this exactly do for my character? If I have a box collision, and translate the character in the scene with a script, what is the main advantage of this component?

    -------------------------

    Further, how would you tie the animation speed of the legs moving to the actual walking speed? Does this work by comparing the old X,Z coordinates with the new one, substracting those and using this value for the animation speed?

    Does Unity allow to interpolate animations - e.g when you stop walking it doesnt stop moving immidiately but does this a bit smooth? (unlike the walker demo).

    Thank you.
    I've been impressed by the support.
    When I'm more experienced with Unity I hope to be able to give it back :)
     
  2. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    The main advantage of the charactercontroller is that it gives the best of both worlds i.r.t. to the rigidbody vs transform problem. Effectively, you ask your characterController to move 5 units to the right. It will move as far as it can, respecting collisions.

    This means you get what is basically an FPS shooter character movement (although I don't see any reason why it wouldn't also work for a 2D platform game). It handles collisions like a rigidbody does, but you move it directly rather than pushing it around with forces.
     
  3. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Thanks!

    The controller seems like the best choice for what I want to achieve. Thank you for the explanation
     
  4. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    I was also wondering about animation control. I appreciate the addition of the loop/clamp/ping-pong options, but I wonder what future animation enhancements you guys are planning for Unity 1.3 and on.

    Matching a character's movement speed to their animation speed could be solved simply by animating it correctly, but it would be extremely helpful if there was a simple speed multiplier for playing clips in Unity, so you could play a clip at 1.4x normal speed through scripting for example. Perhaps more important than that is being able to do blends between clips, ideally blends that are not strictly linear, but have ease-ins and ease-outs. Any chance we'll be seeing something like that?
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    We are planning to add those features to the animation system as an Unity 1.x update.
     
  6. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Mr.Animator, you can't control animation speed by scripting?
    I didnt try it yet, but I assumed it was possible :-/
    I am used to it in Blitz, where you can control animation speed
    by using something like this:

    Code (csharp):
    1. var speed = 5;
    2. var animkind = 1; // ping-pong
    3. var tween = 0.5 // a bit smooth interpolation between animations
    4. anim_walk = extractAnimSeq(object, 0, 50);  // extract from frame 0 to 50
    5. anim_run = extractAnimSeq(object, 51, 90);  
    6. Animate myObject, anim_run, speed, tween;
     
  7. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
  8. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    It looks like you could adjust animation speed with sampleAnimation... shows what I know.

    While we're on the subject of animation control, is there a way to query an object that's playing an animation clip for what frame its currently on? What would be perfect would be a 'currentFrame' animation class variable.
     
  9. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Mr.Animator, please bear with me - I am a newbie :)
    As far as I know isPlaying is the only method to only retrieve true/false for
    the animation playing.

    I think "currentFrame" should be in Unity 1.3, just like general animation speed control. No offense to the developers ofcourse, but these kind of things are essential and for our upcoming projects considered to be a "demand". Coz we're gonna use walking characters with variable speeds (analogue joysticks as input, or slopes that slow down character speed - and animation speed together with it).

    Unity developers please read :D
     
  10. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Here's a simple solution you could use while waiting for us to hear your prayers :)

    If you are using SampleAnimation to control the speed, you already know what frame you're on (actually you know where on the timeline you are, which can be converted to a frame number by dividing by your animation's fps).

    See the docs on SampleAnimation for more information. Basically what you do is that you have a variable containing the current position within the animation, then inside Update use it as the input value to the SampleAnimation function. Then increment the variable by Time.deltaTime a speed factor and make sure the time is within the animation length:

    Code (csharp):
    1.  
    2. var clip : AnimationClip; // assign the animation clip to this property
    3. var fps = 12.0; // set this to match your animation fps
    4. var speedFactor=0.05;
    5.  
    6. private var currentPosition=0.0;
    7.  
    8. function Update() {
    9.      gameObject.SampleAnimation(clip, currentPosition);
    10.      currentPosition += Time.deltaTime * speedFactor;
    11.      currentPosition = currentPosition % clip.length; // makes the animation loop
    12. }
    13.  
    14. function GetCurrentFrame() {
    15.       return currentPosition / fps;
    16. }
    17.  
    18. function JumpToFrame(frameNumber) {
    19.       currentPosition = frameNumber * fps;
    20. }
    21.  
     
  11. dacloo

    dacloo

    Joined:
    Jun 30, 2005
    Posts:
    469
    Smart! Thanks!
    I assume you will add it in a more friendly syntax in the future?
     
  12. Mr. Animator

    Mr. Animator

    Joined:
    Oct 2, 2005
    Posts:
    193
    Thanks for the script, i'll be sure to use that until my prayer's are answered :)

    I'm looking forward to seeing what animation tools you guys roll out next. I'd put those above all else on my wish list, but if you couldn't guess from my handle, I'm a bit of an animation freak. :)
     
  13. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    freyr, this is similar to the Quicktime texture player script (driving the frame with Time.deltaTime). The problem with both of them is you get some frame doubling with the float to int conversion. Any tips on how to avoid this?

    [Edit] I just realized this was unclear... of course you get frame doubling (even tripling, quadrupling), that's how we're artificially changing the playback rate here. My concern with this is that certain frames repeat at the "wrong" time, because of the float/int conversion, causing sync issues. Admittedly this is only a concern for a narrow range of scenarios.
     
  14. freyr

    freyr

    Joined:
    Apr 7, 2005
    Posts:
    1,148
    Just don't convert to and from int. The frame number can be a fraction. Frame 1.5 will show a position halfway between frame 1 and 2.... this of course only applies to Animations.

    For the Quicktime textures, have you made sure that you round the frame index properly?
     
  15. antenna-tree

    antenna-tree

    Joined:
    Oct 30, 2005
    Posts:
    5,324
    Sorry, good point about the animation interpolation, I guess it doesn't apply to that. I honestly didn't know if "baked simulations" worked off of animation curves or step based animation. I've only worked with this regarding QT textures. So use Mathf.Round to get reliable int frames?
     
  16. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Animations in unity and most other game engines use floats measured in seconds.

    This is useful because unlike in maya or other animation programs you don't know the playback speed of your game. Yet you want to display your animations in a smooth way. So the only way to do it is to interpolate between frames based on the current time.

    So you dont need to do anything special. The math keli posted will just work out perfectly fine.