How to change the direction, amplitude and frequency on click of Object that uses sine wave pattern to move
I have a problem with the player script I am developing. the player at default moves in a sine wave pattern, but on clicking on the button I need to change the direction, amplitude, and frequency of the player. I which I am stuck here and I don't know how to code it. To make the problem more crystal clear I need the movement similar to this game: https://www.youtube.com/watch?v=Wr4NTsAthM4&t=35s this is the code of the player : private float ForwardSpeed = 3f; // forward speed of the bird private float DefaultBounceSpeed = 4f; // Default Bouncing speed of the bird private float DefaultAmplitude = 2f; // Default amplitude of the sine private bool Button;
[HideInInspector]
public bool isAlive; // bool
void start(){
isAlive = true;
}
void FixedUpdate(){
if(isAlive){
PlayerMovement(); // controls the movement of the player
}
private void PlayerMovement()
{
Vector3 temp = transform.position;
temp.x += ForwardSpeed * Time.deltaTime;
temp.y = DefaultAmplitude * (Mathf.Sin(DefaultBounceSpeed * Time.time));
transform.position = temp;
}
}
Your answer
Follow this Question
Related Questions
Sin function returns NaN 1 Answer
A graph to render sine wave with custom resolution 0 Answers
Maths question - normalization I think 1 Answer
Find border of Matrix (east, west, north, south) 0 Answers
Making 2D Compass From Quaternion 1 Answer