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.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

CharacterMotor, FPSInputController, PlatformInputController in C#

Discussion in 'Scripting' started by xadhoom, Oct 20, 2010.

  1. ginryu

    ginryu

    Joined:
    Nov 23, 2013
    Posts:
    3
    Ok, I do have an issue with it. In regards to the Charactor Motor. Due to the nature of my project I cannot provide too precise of details, but I will be as accurate as I can be without giving too much away. Basically, my system works by having all my assets stored in the resources folder, and using data I load from a file, these objects are loaded into the game scene at runtime, When testing a map I created using my system, when spawning in the character(With CharacterMotor already attached) the charactor spawns in at 0,0,0. The world center. despite spawning in at a spawn point map object at a much different position. When the CharacterMotor is not attached, the character appears right where it is supposed to be.

    I believe the issue is either in the ApplyInputVelocityChange or the ApplyGravityAndJumping functions.
    Since nothing in there sets the default variables used in those cases to the charactors transform position, When these functions are used, it results in the charactor appearing at the default co-ordinates. Oddly enough, this is not an issue for Character models already present in the scene, or dragged into the scene via the Editer, its only when spawning a character in.

    if I am right, I would suggest implementing a defaulting method to ensure that the character appears right where it is supposed to appear when being spawned in, as this will affect the ability to have enemies spawn in at spawnpoints and such when creating games such as rpgs and fps.

    Edit: Tried leaving the CharacterMotor unattached until it was time to spawn the character. At Spawn time, I attached the CharacterMotor to the Character, but still wound up with the same result as before. Incorrect positioning. Something in there is defaulting my Characters Position to the world center.

    Edit2 It is indeed a problem somewhere within the functions I pointed out above. In order to fix the issue, I set up an defaulting function which sets the players position to the spawn position.
    as well as a variable that is enabled via a coroutine, when the character spawns in, I send in the command to default the character, and then call a coroutine that waits for a couple seconds so that the whole script can initialize properly, then sets the variable that allows the update and fixed update functions to do their things. Everything works now, aside from not being able to move the character aside from jumping. but that is at least 1 issue out of the way for now
     
    Last edited: Aug 11, 2019
  2. EricST

    EricST

    Joined:
    Sep 20, 2014
    Posts:
    1
    Thank you for these. Saved me a some recoding.