update AI
This commit is contained in:
36
Assets/TeKniKo_Free/Power_Ups/Scripts/ObjectBounce.cs
Normal file
36
Assets/TeKniKo_Free/Power_Ups/Scripts/ObjectBounce.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectBounce : MonoBehaviour
|
||||
{
|
||||
public float bounceSpeed = 8;
|
||||
public float bounceAmplitude = 0.05f;
|
||||
public float rotationSpeed = 90;
|
||||
|
||||
private float startHeight;
|
||||
private float timeOffset;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
startHeight = transform.localPosition.y;
|
||||
timeOffset = Random.value * Mathf.PI * 2;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//animate
|
||||
float finalheight = startHeight + Mathf.Sin(Time.time * bounceSpeed + timeOffset) * bounceAmplitude;
|
||||
var position = transform.localPosition;
|
||||
position.y = finalheight;
|
||||
transform.localPosition = position;
|
||||
|
||||
//spin
|
||||
Vector3 rotation = transform.localRotation.eulerAngles;
|
||||
rotation.y += rotationSpeed * Time.deltaTime;
|
||||
transform.localRotation = Quaternion.Euler(rotation.x, rotation.y, rotation.z);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user