How can i make an object (a cube) change the surface or plan of the game?
Hello everyone, i have a problem and hope you help me please
Ich have a cube or a sphere o. The sphere moves only between the surfaces (1), (2), (3) , (4) (over surface 1, under surface 2, over surface 3 and under surface 4). At the start the cube has already a speed. That means it moves from the left to the right automatically, and when the user touch the screen, the object slide (or jump) to the other surface, from (1) to (2), then (2) to (3), (3) to (4) and so on, and only between them and not over(surface 2 and 4)
(2)
=================
(4)
o (1) =================
=============
(3)
=====================================
Please help me this to realize that
Answer by Le-Pampelmuse · Mar 17, 2016 at 09:27 AM
Unity Answers will not help you create basic games, it is meant for serious questions about problems with Unity. If you are looking for tutorials, Google is your best choice ;)
Please make sure your questions are appropriate for Unity Answers before asking them. Check the FAQ.
There is confusion among many moderators and they publish everything sadly.
If you are following tutorials and have trouble to understand them, you should watch the beginner tutorials made by Unity in the Learn Section.
Hi, If a moderator publishes a question, it means that the question is worthy or has the requirements to be published. If you have no idea about the issue, it is not a problem. You do not need to write something, but if it is not the case, then we(the community and i) would be very happy that you share it with us. Thank you!
That's not correct. If I publish a question that is pure spam (which happens regularly during spambot attacks) , is it worthy of being on UA? Does it meet the required standards? I dont think so.
Everyone becomes a moderator at 1000 reputation, it is not a choice. It's a common problem (with almost any community-moderated forum) that many moderators binge-publish questions from the mod queue because they want to be friendly or simply and seriously don't know how to handle the tasks of moderating.
I didn't mean to sound rude or condescending in any way, if I did to you, I apologize.
Taking on to your Question, what exactly do you want to achieve? Correct me if I'm wrong:
A sidescrolling platformer mobile game
Player has to jump to reach the next platform, if he jumps in between, he loses/dies
Player sticks to the upper part of low platforms, and to the bottom part of high platforms.
Done
What I would suggest for the issue of top or bottom platforms (keep in $$anonymous$$d this is a subjective idea):
Have a prefab rectangle for the platforms. Add a child box collider to each the "good" side and the "bad" side, tag those colliders accordingly, good and bad.
Now use built-in collider functions like OnCollisionEnter2D to check when the player collider is touching another collider (meaning a platform). Check via the tags if it is a good touch, the player keeps moving, if it is a bad touch (lol) the player loses a life and restarts at the beginning or a checkpoint based on your game.
I guess this is your biggest obstacle, how to implement this functionality.
Feel free to ask if something is not understandable.
Thanks for the reply. i try to improve my knowledges, i want to make something like this ninja game . he runs under or above a surface. the problem that i have is when i jump to the surface above. he doesnt stay on the surface above. He falls down
Ok thats is what i currently try to do
void Update()
{
if (Physics.Raycast(transform.position, -Vector3.up, raycastDistance))
{
// I check, if the object is on the ground or bottom
isGrounded = true;
airJumpCnt = maxJumpCnt;
}
else
{
isGrounded = false;
}
// i give the object a speed value if it is the case
if (isGrounded)
{
rb.velocity = Vector3.right * xSpeedLev; // oder 5
//countEins = 0;
}
$$anonymous$$ouseInput();
}
private void $$anonymous$$ouseInput()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
//countEins++; // how many times i hit the top or the bottom
selObj = EventSystem.current.currentSelectedGameObject;
if (selObj == null || selObj.gameObject.tag != "UIButton" || selObj.gameObject.tag != "Finish")
{
isGrounded = false;
//try to jump with 45° up to the top and then with 45° down to the bottom
rb.velocity = new Vector3(xSpeed, normalJumpForce, 0f);
}
}
}
Sorry for reacting so late I didn't get a notification about it.
DId you post this intentionally as an answer? Is this your solution?
Edit: I just converted your answer to a comment on my Question because I feel like you were asking for guidance with your script attempt and not giving a final solution.
Feel free to ask what you are having problems with. Don't leave your Questions open and comments unanswered ;)
Answer by Roddeck · Mar 19, 2016 at 03:15 PM
Well, you could write something that ignores colliders if ninja is below platform and enables them if he is above.
That won't do much because then the game would be only about moving on top of platforms, not both. Please read Q's carefully before answering ;)