Quantcast
Viewing all articles
Browse latest Browse all 120

Why is this happening when I run my script?

My script here is supposed to make an object bounce when it touches a touchpad, but I did not want to use rigidbody, so I used this instead. But when running the script, instead of bouncing it teleports. This is the script. using System.Collections; using System.Collections.Generic; using UnityEngine; public class Bounce : MonoBehaviour { //adjust this to change speed [SerializeField] float speed = 5f; //adjust this to change how high it goes [SerializeField] float height = 0.5f; Vector3 pos; private void Start() { pos = transform.position; } void OnTriggerEnter(Collider collision) { if (collision.gameObject.tag == "jumpPad") { //calculate what the new Y position will be float newY = Mathf.Sin(Time.time * speed) * height + pos.y; //set the object's Y to the new calculated Y transform.position = new Vector3(transform.position.x, newY, transform.position.z); } } }

Viewing all articles
Browse latest Browse all 120

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>