I have this script below which moves a platform backwards and forwards.
I would like to be able to add a rotation to it so that as the platform travels backwards and forwards it turns to face the way it is going. I’ve tried several things I found on Unity Answers but just get a whole bunch of errors even though I’ve been very careful to follow the syntax (as far as I can) Any help would be greatly appreciated, thank you.
Here is the script I have that moves the platform:
#pragma strict
private var old_pos : Vector3;
var move : boolean = false;
var speed : float = 1;
var time_shift : float = 0.0;
var move_by : Vector3;
function Start() {
old_pos = transform.position;
tag = "platform";
}
function LateUpdate () {
if(move)
transform.position = Vector3.Lerp(old_pos, old_pos + move_by, (Mathf.Sin((Time.time + time_shift) * speed) + 1) / 2);
transform.eulerAngles = Vector3.zero;
}
Hey RHD.
So…I have built you a small grey box with a platform that can be rotated on the left mouse click, provided your cursor, in game, is placed on the platform.
To stop it you have to hold the “m/M” key on your keyboard and again point at the platform and click the left mousebutton.
I have added some suggestions in the code to (PlayerGameInput and Platform scripts) as to how to obtain a simple angular change from one to another or the other potential to rotate the platform a set angle a time.
This is in the code, so please read that to see what i mean.
So I havent fixed your problem for you, with respect to completely doing your job for you, in the nicest possible sense. Instead, I have provided you with a set of tools that can be used to complete your goal, but the caveat is that you must mould it, otherwise you may never get to a point where you can feel you could provide others with the help they need to understand all this Unity stuff. Hope that makes sense, as I mean it in the best possible light.
If the package has any issues, let me know, but all shoudl work well…
To clarify my warbled mess above…
Just import package in to unity(v.4) and click the scene, then play, point to platform, left click - to start rotation, hold “m” and left click to stop rotation.
Look at the code, I promise you could change it to exactly what you are looking for, I have already done so to make sure, so what I have said in the code should guide you enough to discover the right path to euphoric feeling of solving one problem to find another almost as quick
Good luck RHD, let me know how it goes if you want.
Gruffy
[5867-rotateplatform.zip|5867]
Hey RHD.
Right if you go to the script and try to find what the y value and speed are represented as, you should be able to represent them outside of any fucntion publically in js or declare them public “data type(being float,int etc)” your_var_name
Im not hot on the js semantics im afraid, but you could easily look up how to get your var into the Object inspector.
As for c# this is how below
public float myYRotationScale = 0;
public float speed = 10;
//these can then be changed in the inspector at your whim.
If you post your script, I & others can see it and maybe point you to the right areas to change/addend or even quickly do it for you.
Cheers bud, hope it all makes some sort of sense
Gruffy