Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Launch Pad Issues

Discussion in 'Scripting' started by VandalPwoof, Jul 13, 2017.

  1. VandalPwoof

    VandalPwoof

    Joined:
    Feb 17, 2017
    Posts:
    23
    I would like to preface this by stating that I have already referred to other relevant threads such as
    https://forum.unity3d.com/threads/creating-a-jump-pad-in-c.312774/ . However, I am still unable to cause the Player GameObject's jump value to change upon collision of the Jump Pad.

    This is the Jump Pad code.
    The Player GameObject has already been designated to the "Player" GameObject.

    Please help me on this. I am creating a platformer game with interactable objects that can modify the Player's movement speed parameters, jump values, and etc upon walking on the relevant pads.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class JumpModify : MonoBehaviour {
    6.     public float thrust = 50f;
    7.     public GameObject Player;
    8.  
    9.     void OnTriggerEnter(Collider PlayerCtrl)
    10.     {
    11.         PlayerCtrl.transform.TransformDirection (Vector3.up * thrust);
    12.     }
    13. }
    This is the Player Controller code.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.     public float speed = 6.0F;
    7.     public float jumpSpeed = 8.0F;
    8.     public float gravity = 20.0F;
    9.     public Rigidbody rb;
    10.  
    11.     private Vector3 moveDirection = Vector3.zero;
    12.  
    13.     void Start()
    14.     {
    15.         rb = GetComponent<Rigidbody>();
    16.     }
    17.  
    18.     void Update ()
    19.     {
    20.         CharacterController Player = GetComponent<CharacterController>();
    21.         if (Player.isGrounded) {
    22.             moveDirection = new Vector3 (Input.GetAxis ("Horizontal"), 0, 0);
    23.             moveDirection = transform.TransformDirection(moveDirection);
    24.             moveDirection *= speed;
    25.             if (Input.GetButton("Jump"))
    26.                 moveDirection.y = jumpSpeed;
    27.         }
    28.         moveDirection.y -= gravity * Time.deltaTime;
    29.         Player.Move(moveDirection * Time.deltaTime);
    30.     }
    31. }