- Home /
Platformer object control
I have a platformer game that has a bunch of red and blue cubes. and i need a way/script so that everytime i press say alt, either the red or the blue cubes come into play. so basically on alt they would shift back and forth into line of play. THanks.
By "come into play" do you mean the cube then becomes the players controllable character?
Are you trying to switch the players controllable character between the red and blue cubes on the press of a key?
Sorry should have been more clear. erm. you dont play as the cubes but i want them to be platforms that when i press alt either hte red or the blue ones come into the same line as the player and you can jump on them. when the red ones are able to be used the other ones will go back into the background a little. it only needs to move the red and blue cubes back and forth on a touch of a button.
. _
. .
. .
_ .
Like so? "_" is a cube "." is movement.
So you press Alt once, the red cube comes forward, press it again and the red goes back and the blue comes forward?
i clearly suck at explaining things ahah. But yeah you got the idea.:)
Well there are 2 ways i can think to do this:
iTween (by far the easiest)
using an animation thats played "Input.On$$anonymous$$eyDown"
Do you use iTween?
I will do my best to point you in the right direction if not.
Answer by timsk · Sep 27, 2011 at 12:06 PM
I highly suggest iTween, makes any kind of movement so easy (i also suggest the iTween visual editor, reduces the amount of coding needed):
http://itween.pixelplacement.com
http://dkoontz.wordpress.com/itween-visual-editor/
if using iTween, you can use this code to move the platform:
function MovePlatforms()
if(Input.GetButton ("definekey")
{
iTween.MoveAdd(gameObject,Vector3(5,0,0),2)
}
Like i said, its easier with the visual editor.
If you don't want to use iTween. You can create an animation where 1 cube moves forward and the other back and then use this:
function MovePlatforms()
if(Input.GetButton ("definekey")
{
Animation.play("moveplatforms");
}
//you can use Animation.Rewind("moveplatforms"); or animation["moveplatforms"].speed = -1.0;to play animations backwards
Heres some references to help you:
http://unity3d.com/support/documentation/ScriptReference/Animation.html
http://unity3d.com/support/documentation/ScriptReference/WrapMode.html (ClampForever should work for this)
http://unity3d.com/support/documentation/ScriptReference/AnimationState.html
Good luck! :)
made me feel all fuzzy inside ^^.
Just another note. Look into switch...case statements, if you had more than 2 cubes, you would probably need to use one of those. I'm not great with them, so cant really help you.
Hope your games goes well!
Is there a reason why its saying unknown identifier 'iTween' its in the same folder it should be picking it up :/
make sure the iTween files are located in the "Plugins" folder in your project.
ahah all fuzzy is good :P and i dont seem to have a plugins folder. Just make one? and i found out that my itween file is in c# is that ok if its being sorced through a javascript?
Your answer
Follow this Question
Related Questions
What's Tight Gameplay? 1 Answer
getting udp package info inside unity (GlovePIE) 0 Answers
2D 360 degress platformer example needed 0 Answers