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

Unity3D: Platformer Character (Help needed)

Discussion in 'Scripting' started by MichaelTheAvali, Mar 1, 2020.

  1. MichaelTheAvali

    MichaelTheAvali

    Joined:
    May 10, 2017
    Posts:
    37
    I've gotten tired of using the invector Third Person Controller for making my game because I'm unable to access the speed varibles from the script to modify in another script for boost panels and such, so I'd like some help to make a platformer character script (Third Person controller except the player moves freely instead of strafing)

    To add on, I dont want root motion as it messes with the character i'm using
     
    Last edited: Mar 1, 2020
  2. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,337
    Where is the question? What's the actual problem you're having?
     
  3. MichaelTheAvali

    MichaelTheAvali

    Joined:
    May 10, 2017
    Posts:
    37
    Well I'm trying to make a sonic character controller (well a normal platformer controller but the speed varibles can be changed), but every controller i've used either doesnt work with my character, is too old to work, or just wont let me access the speed varibles at all (Invector has the speed varibles in another class and I have no idea how to access them to modfiy my character's max speed temporally)

    For my invector problem, this is whats going on

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Invector.vCharacterController;
    5.  
    6. public class SonicModifier : MonoBehaviour
    7. {
    8.     public vThirdPersonController PlayerController;
    9.  
    10.     float fixedRunSpeed;
    11.     float fixedAirSpeed;
    12.     public int Multiply;
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         PlayerController = gameObject.GetComponent(typeof(vThirdPersonController)) as vThirdPersonController;
    19.         fixedAirSpeed = PlayerController.airSpeed;
    20.         fixedRunSpeed = PlayerController.vMovementSpeed.runningSpeed;
    21.     }
    22.  
    23.     // Update is called once per frame
    24.     void Update()
    25.     {
    26.     }
    27. }
    and the error
    Assets\Michael's Assets\Scripts\SonicModifier.cs(20,42): error CS0572: 'vMovementSpeed': cannot reference a type through an expression; try 'vThirdPersonMotor.vMovementSpeed' instead

    along with this too
    Assets\Michael's Assets\Scripts\SonicModifier.cs(20,25): error CS0120: An object reference is required for the non-static field, method, or property 'vThirdPersonMotor.vMovementSpeed.runningSpeed'


    And because of this, I'm wanting to give up with Invector and just make my own script, but the problem is getting the player to move reletive to the camera, without rotating them towards where the camera is looking
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,337
    Haven't used invector. Your error messages indicate that vMovementSpeed is not a property of a PlayerContrller, but a type or a nested class. That's why you can't access runningSpeed. Refer t the documentation and see proper way to access it. Judging by the piece of code you provided, Invector package uses a non-standard naming convention where types start with lovercase v letter. See if there's PlayerController.groundSpeed or something similar.
     
  5. MichaelTheAvali

    MichaelTheAvali

    Joined:
    May 10, 2017
    Posts:
    37
    I'll also mention that the problem is that there's multiple scripts for this, and they are all combined into one

    vThirdPersonMotor is where all the movement data is stored
    vThirdPersonController is the main script, and it's a child of vThirdPersonAnimator, which is also a child of vThirdPersonMotor, and i have no idea how to access that far back when the main script is vThirdPersonController

    vThirdPersonAnimator has the varible i need exposed outside of the class however
     
  6. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,337
    I'll explain.

    vThirdPersonController is likely declared like this:
    Code (csharp):
    1.  
    2. public class vThirdPersonController{
    3.     public class vMovementSpeed{
    4.         //stuff
    5.     }
    6.     //stuff
    7. }
    8.  
    Somewhere within the class there may be something like
    "public vMovementSpeed groundMovement".
    I.e like this.
    Code (csharp):
    1.  
    2. public class vThirdPersonController{
    3.     public class vMovementSpeed{
    4.         //stuff
    5.     }
    6.     public vMovementSpeed groundMovement;
    7.     //stuff
    8. }
    9.  
    And THAT"s what you'll want to access. Depending on design it could also be a component.

    Instead of that you're trying to access vThirdPersonController.vMovementSpeed, which is a TYPE and not a THING of some Type.
     
  7. MichaelTheAvali

    MichaelTheAvali

    Joined:
    May 10, 2017
    Posts:
    37
    The vMovementSpeed isnt in the controller, its in the motor script.
    The controller script is the script that needs putting on a gameobject to make it work