Unity Ninja Unity 3D Forum
To have exclusive access to all downloads, recourses and links within this forum, a free registered account is required. Just a heads up Wink

You are not connected. Please login or register

Unity Ninja Unity 3D Forum » HELP » Help (General) » [NEED HELP] Moving object as wave !!!!

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

View previous topic View next topic Go down  Message [Page 1 of 1]

1 [NEED HELP] Moving object as wave !!!! on Tue Oct 04, 2016 9:49 pm


Member [Lv. 1]
Member [Lv. 1]
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.

View user profile

2 Re: [NEED HELP] Moving object as wave !!!! on Sat Oct 08, 2016 7:04 pm

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)

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.

View user profile

View previous topic View next topic Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum