UnityNinja Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

UnityNinja CommunityLog in

UnityNinja - Video Game Development Community, including Resources, Forums, Marketplace & More.


description[NEED HELP] Moving object as wave !!!! Empty[NEED HELP] Moving object as wave !!!!

more_horiz
Hi, i'm facing a problem, i'm searching for a week but got nothing, i want to move object exactly like this. Please help me !!!(resource, keyword.....). Sorry for my bad English! Thanks for reading.
https://www.youtube.com/watch?v=EfLVpMn8OKc

description[NEED HELP] Moving object as wave !!!! EmptyRe: [NEED HELP] Moving object as wave !!!!

more_horiz
Hello, quangtien. For that, you would need to use a sine function. (Mathf.Sin)
I'll give you an example of what the code should look like. (in javascript)

Code:


var current_y : float; //The y of the object (before sin)
var change_y : float; //How fast you want it to change
var mult : float; //How far to go (like up or down)
var obj : Transform; //Object to move

function Update () {
 current_y += change_y;
 if (Input.GetKey (KeyCode.Space)) {
  mult = 5;
 } else
  mult = 1;
 }
 if (current_y > 360) current_y -= 360;
 obj.position.y = Mathf.Sin (current_y) * mult
}


That should be good. You should know some about trigonometry if you want to make scripts like this. This might be hard to understand without trigonometry.
privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply