Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How can in modify my Vertical moving Platform code ( Unity , C# ) to creat a script thats makes platforms move in a circular

How can in modify my Vertical moving Platform code (Unity, C#) to creat a script thats makes platforms move in a circular motion? using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class V_Moving_Platforms : MonoBehaviour
{
[SerializeField] private Transform topedge;
[SerializeField] private Transform bottomedge;
[Header("Platform")]
[SerializeField] private Transform platform;
[Header("Movement Parameters")]
[SerializeField] private float speed;
private Vector3 initScale;
private bool movingUp;
[Header("Idle Time")]
[SerializeField] private float idleDuration;
private float idleTimer;
private void Awake()
{
initScale = platform.localScale;
}
//Adapt for vertical moving platform
void Update()
{
if (movingUp)//if platform moving up
{
//if platform posotion y is greater than or equak to bottomedge position y
if (platform.position.y >= bottomedge.position.y)
{
//call MoveInDirection function and pass -1 as argument
MoveInDirection(-1);
}
else
{
// calls change direction
DirectionChange();
}
}
else
//if platform pos Y is less than or equal to the top edge Y positio
if (platform.position.y <= topedge.position.y)
{
//calls MoveInDirection functioin and passes 1 as an argument
MoveInDirection(1);
}
else
//change direction
DirectionChange();
}
private void MoveInDirection(int _direction)
{
//set idleTimer to 0
idleTimer =0;
//makes platform move
platform.position = new Vector3(platform.position.x, platform.position.y + Time.deltaTime *_direction * speed, platform.position.z);
}
//Change Direction Functiom
private void DirectionChange()//change direction of platform
{
idleTimer += Time.deltaTime;
//if idleTimer is greater than idleDuration
if (idleTimer > idleDuration)
{
//reverse direction
movingUp =!movingUp;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Greed And Fear Understanding Behavioral Finance And The Psychology Of Investing

Authors: Hersh Shefrin

1st Edition

0195161211, 978-0195161212

Students also viewed these Databases questions