Search Unity

Horse Script?

Discussion in 'Scripting' started by UndeadMadison, May 8, 2020.

  1. UndeadMadison

    UndeadMadison

    Joined:
    Apr 16, 2020
    Posts:
    15
    Hey! So the game I’m working on has the ability where the player is able to mount, ride and dismount a horse but I don’t exactly know how to do that. I used the first person controller unity gives for both my player and tried to do it for my horse as well. It didn’t go as planned. The controls are inverted when riding the horse so “W” is “D” and “A” is “S”. Along with that the horse either falls through the terrain or as soon as the player switches to the horse it moves of the ground, well teleports off the ground and just stays in the air. I don’t know if I’m using the wrong controller for this, if it’s my model or if I should just make a scratch controller script for it. I know there is a pack on the store that has the essentials to do what I’m trying to do but I want to do this all free for all my games. If anyone knows how to help me, thank you so much I appreciate the help! If you would like I can put up pictures of what the horse does if needed.
     
  2. csofranz

    csofranz

    Joined:
    Apr 29, 2017
    Posts:
    1,556
    Well I guess the first step is to show us your code and where you beed help. From your description it seems that you are using two controllers . so write a unified one, and when that breaks down, post the code here for us to try and help.
     
  3. UndeadMadison

    UndeadMadison

    Joined:
    Apr 16, 2020
    Posts:
    15
    Thank you for responding! Like I said in the message I used the First Person Controller for both the player and horse so I didn't have to do much code. Here is what I did and what happens when the player gets on the horse. I also just found out that every time I try to play the game in Unity it just crashes the whole thing. Here is my code:


    public float distance;

    public GameObject actionDisplay;
    public GameObject extraCursor;
    public GameObject player;
    public GameObject horseCam;
    public GameObject horse;

    void Start()
    {
    horse.GetComponent<FirstPersonController>().enabled = false;
    horseCam.SetActive(false);
    }

    void Update()
    {
    distance = PlayerCasting.distanceFromTarget;
    }

    void OnMouseOver()
    {
    if(distance <= 3)
    {
    actionDisplay.SetActive(true);
    extraCursor.SetActive(true);
    } else { actionDisplay.SetActive(false); extraCursor.SetActive(false); }

    if (Input.GetButtonDown("Interact") && distance <= 3)
    {
    player.transform.parent = horse.transform;
    player.GetComponent<FirstPersonController>().enabled = false;
    horse.GetComponent<FirstPersonController>().enabled = true;
    horseCam.SetActive(true);
    }
    }
     
  4. UndeadMadison

    UndeadMadison

    Joined:
    Apr 16, 2020
    Posts:
    15
    Sorry if it looks odd, I am still new at the forums.
     
  5. UndeadMadison

    UndeadMadison

    Joined:
    Apr 16, 2020
    Posts:
    15
    I had to download unity again and I can’t use the Standard assets anymore so I have to make a controller from scratch now to do this.