Question by
Blaze400 · Aug 08, 2021 at 12:22 AM ·
unity 5c# tutorialforums
Can't Figure Out How To Make Bounce Pad
Hello, I'm trying to make a bounce pad that when I jump on top of it makes me go high (Height can be set from unity) and also plays an animation when doing so, I'm a noob to c# and unity so please explain this to me as if I'm a 5 year old. ty :D.
my code...
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bouncepad : MonoBehaviour
{
public PlayerMovement playermovement;
public Animator anim;
public float BounceHeight = 20f;
void Start()
{
anim = GetComponent<Animator>();
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player") {
GameObject Player = GameObject.Find("Player");
PlayerMovement playermovement = Player.GetComponent<PlayerMovement>();
playermovement.jumpHeight = BounceHeight;
void Update()
{
if(Input.GetButtonDown("Jump"))
{
anim.Play("bounce pad spring");
}
}
}
}
}
This is my player controller (brackeys tutorial)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;
public float speed = 12f;
public float gravity = -9.81f;
public float jumpHeight = 3f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
// Update is called once per frame
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward *z;
controller.Move(move * speed * Time.deltaTime);
if(Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Same code but code not working ? 0 Answers
Where can I learn C# 3 Answers
Button onclick problem. 0 Answers