Questions in topic: "mario"http://answers.unity.com/questions/topics/single/995.html
The latest questions for the topic "mario"How to do an automatic scroll level in a 2D mobile game like in mario's game ?http://answers.unity.com/questions/1624488/how-to-do-an-automatic-scroll-level-in-a-2d-mobile.html
Hi i just would like help for my project, I'm want to make an little game for android, I would like to know how to do an automatic scolling level like mario ( https://www.youtube.com/watch?v=wbwl7-JiTvA )
and if possible, an scrolling level which the camera goes from up to down. Thanks for helping me.scrollviewscrollingautomaticmarioMon, 22 Apr 2019 19:30:48 GMTozan036777Mario Powerups Switching problem,Mario PowerUps Switch problemhttp://answers.unity.com/questions/1613267/mario-powerups-switching-problemmario-powerups-swi.html
Hello, my name is Reno. I am a beginner in programming and I want to program a game. My first game is a Mario Clone. I programmed it so that there is a game object for each powerup form. Each time Luigi touches the mushroom, the game object has to be changed. My problem is that when Luigi touches the mushroom, the gameobjects are switching nonstop per milisecond. Its kinda hard to explain.
![alt text][1]
[1]: /storage/temp/134870-sefsefsefswef.png
I hope you understand what I mean. When Luigi touches the mushroom he should switch with the big gameobject and stay in that form. Now they are switching betwen those two.
This is my Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collecter : MonoBehaviour
{
public GameObject LilMario, BigMario;
int whichMarioIsOn = 1;
void Start()
{
LilMario.gameObject.SetActive(true);
BigMario.gameObject.SetActive(false);
}
void Update()
{
SwitchMario();
}
public void SwitchMario()
{
switch (whichMarioIsOn)
{
//Default case
case 1:
whichMarioIsOn = 1;
LilMario.gameObject.SetActive(true);
BigMario.gameObject.SetActive(false);
break;
//Big case
case 2:
whichMarioIsOn = 2;
LilMario.gameObject.SetActive(false);
BigMario.gameObject.SetActive(true);
break;
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Pilz")
{
whichMarioIsOn = 2;
Debug.Log("2 aktiv");
Destroy(other.gameObject);
}
}
}
I think the problem is in the update method.
I hope you understand it and can help me.
Thx for every answers have a nice day !,Hello, my name is Reno. I am a beginner in programming and I want to program a game. My first game is a Mario Clone. I programmed it so that there is a game object for each powerup form. Each time Luigi touches the mushroom, the game object has to be changed. My problem is that when Luigi touches the mushroom, the gameobjects are switching nonstop per milisecond. Its kinda hard to explain.
![alt text][1]
[1]: /storage/temp/134869-sefsefsefswef.png
I hope you can understand what I mean. I want that when Luigi touches should the bigLuigi appear and stay. But now both are switching nonstop.
This is my Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Collecter : MonoBehaviour
{
public GameObject LilMario, BigMario;
int whichMarioIsOn = 1;
void Start()
{
LilMario.gameObject.SetActive(true);
BigMario.gameObject.SetActive(false);
}
void Update()
{
SwitchMario();
}
public void SwitchMario()
{
switch (whichMarioIsOn)
{
//Default case
case 1:
whichMarioIsOn = 1;
LilMario.gameObject.SetActive(true);
BigMario.gameObject.SetActive(false);
break;
//Big case
case 2:
whichMarioIsOn = 2;
LilMario.gameObject.SetActive(false);
BigMario.gameObject.SetActive(true);
break;
}
}
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == "Pilz")
{
whichMarioIsOn = 2;
Debug.Log("2 aktiv");
Destroy(other.gameObject);
}
}
}
I think the problem is in the void Update Method.
I hope you can help me.
Thx for every Answer.clonepowerupswitch-casemarioswitch charactersSun, 17 Mar 2019 08:49:17 GMTunity_l5gXvpRu2FDjmQMario Camera Culling Mask (Secret Areas),http://answers.unity.com/questions/1594024/mario-camera-culling-mask-secret-areas.html
I have been trying to figure out how this is done. I can only imagine that there are 2 cameras that are displaying the foreground and the hidden section based on layers. However I am unable to recreate this or find a way to do it. Any ideas? ![alt text][1]
[1]: /storage/temp/131898-mask-maybe.png
,cameramaskmaskingculling maskmarioThu, 24 Jan 2019 18:36:04 GMTSwampRabb1tMario jump addforce problemhttp://answers.unity.com/questions/1523522/mario-jump-addforce-problem.html
Hi, I need help with jumping like a mario. I found this solution on the Internet, but I don't like the physics of the jump because of the velocity. When changing to addforce, only a short jump works, as it is not respected (rb.velocity.y> jumpMinForce). I can not understand what condition to ask and what to change, so that everything works with Addforce. Thank you
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BetterJump_2 : MonoBehaviour {
public float jumpMinForce = 3f;
public float jumpForce = 10f;
bool jump = false;
bool jumpCancel = false;
public LayerMask whatIsGround;
private bool isGrounded = false;
public Transform groundCheck;
private float groundRadius = 0.2f;
private Rigidbody2D rb;
void Awake (){
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround);
// Check ground
if (Input.GetButtonDown("Jump") && isGrounded) // Start Press Jump
jump = true;
if (Input.GetButtonUp("Jump") && !isGrounded) // Stop Press Jump
jumpCancel = true;
}
void FixedUpdate()
{
// Simple Jump
if (jump)
{
rb.AddForce(Vector2.up*jumpForce, ForceMode2D.Impulse);
// rb.velocity = new Vector2(rb.velocity.x, jumpForce);
jump = false;
}
// Cancel Jump
if (jumpCancel)
{
if (rb.velocity.y > jumpMinForce)
// rb.velocity = new Vector2(rb.velocity.x, jumpMinForce);
rb.AddForce(Vector2.up*jumpMinForce, ForceMode2D.Impulse);
jumpCancel = false;
}
}
}jumpaddforcemarioholdingFri, 29 Jun 2018 11:21:19 GMTloony220792Mario-Like 2D platformer (Bill Blaster)http://answers.unity.com/questions/1499253/mario-like-2d-platformer-bill-blaster.html
I'm doing a school project to make a game like super mario bros on unity3d using design patterns, and i'm making the bill blaster. i already made it instantiate the bill bullets but i don't know how do i make the bullet blaster detect on which side is the player so it will shot the bullets that way.
this is what i've done so far
public class Bill_Blaster_Demo : MonoBehaviour {
public Transform BB_Spwan; // Where the bullet gets instantiated from
public EnemyManager em;
public GameObject bb; //the Bullet Bill
float spawnWait = 2.5f;
float destroyWait = 10f;
IEnemies Bill_blaster;
void Start ()
{
Bill_blaster = em.GetEnemy(gameObject.tag);
Bill_Blaster.setTransform(BB_Spwan);
StartCoroutine(Spawn());
}
IEnumerator Spawn()
{
while (true)
{
Bill_blaster.Move(bb);
yield return new WaitForSeconds(spawnWait);
}
}
}2d-platformerturretmarioThu, 26 Apr 2018 20:53:39 GMTKh_Shoukrysuper mario bros 3 sytle 3D platformer enginehttp://answers.unity.com/questions/1355019/super-mario-bros-3-sytle-3d-platformer-engine.html
I'm need 3D platformer script with:
-variable jump
-walk rund and if hold down the run button some time sprint and jump bigger
-crouch with jump and spin
please dont write super character control(ler)
thank to helpjumpplatformersystemmarioThu, 18 May 2017 13:42:53 GMTareTeamHow might I render a Mario Galaxyesque Invincibility trail?http://answers.unity.com/questions/1310184/how-might-i-render-a-mario-galaxyesque-invincibili.html
![alt text][1]
[1]: /storage/temp/87595-super-mario-galaxy-2-invincible.jpg
How might I go about rendering a trail like the picture? Using a mesh in the particle system only allows for unposed meshes, where these are like different posed snapshots of the time of spawn.
Creating instanced gameobjects of the animated mesh seems inefficient and complicated. Right now, I'm experimenting with SkinnedMeshRenderer.BakeMesh to bake out the skinned mesh as a static mesh to an array, then using Graphics.DrawMesh to draw them. I'm wondering if I'm on the right track, if there are things to consider in doing it that way, or if there's a better way altogether.particlestraildrawmeshmarioThu, 09 Feb 2017 07:05:43 GMTianlarsonHow to make a Mario like hub worldhttp://answers.unity.com/questions/1275634/how-to-make-a-mario-like-hub-world.html
Hey i'm making a prototype hub world to learn more about unity 5. I'm trying to make it like Super Mario 3D land where the hub world is a 3D plain. Dose anyone have any suggestions?3dlevelsscene-changemarioThu, 24 Nov 2016 04:28:23 GMTDatSamGamerPaper Mario Path Effecthttp://answers.unity.com/questions/1254426/paper-mario-path-effect.html
Hi, I have been trying to create a path like paper mario for some weeks now. I don't know much about shaders but I know that I have to have a plane below that will be the path, and I probably will need some quads with some texture to mask the green floor to show the red path.
Any Ideas of how create that effect?
Thanks for your time.
![alt text][1]
[1]: /storage/temp/79851-wiiu-papermariocolorsplash-screen-01-bmp-jpgcopy.jpgpathmaskmaskingmarioMon, 10 Oct 2016 13:25:57 GMTt-pedrobMario moves highground?http://answers.unity.com/questions/1144221/mario-moves-highground.html
Maybe all of us played Mario. im making **[Super Mario World][1]**... and this is my problem, please help !!!
[alt text][2]
HOW CAN I MOVE TO HIGHGROUND?
1. if i was in normal ground, i can run through highground. (highground's box - trigger?)
2. if i jumped, landed in highground (highground's box non-trigger?)
3. Only when landed in highground, it will be non-trigger?
PLEASE HELP ME? ANY SOLUTION? USE RAYCAST?
[1]: http://www.spriters-resource.com/snes/smarioworld/
[2]: /storage/temp/64192-marioupground.jpgsolutionmarioThu, 18 Feb 2016 20:09:03 GMTAndrew-Leam getting this error in my script - `EnemyAI.CheckGround(UnityEngine.Vector3)': not all code paths return a valuehttp://answers.unity.com/questions/1111452/am-getting-this-error-in-my-script-enemyaicheckgro.html
here is my script the error is on line 78 Vector3 CheckGround (Vector3 pos) {
I have tried several ways to correct this but still coming up with the same issue - how do I go about writing this code so I can fix this error or what do I need to change in the script so this can work properly - I tried using a debugger but of course it wouldn't tell me a solution on how to fix the issue. - if anyone can help me I would appreciate it
thanks in advance
public class EnemyAI : MonoBehaviour {
public float gravity;
public Vector2 velocity;
public bool isWalkingLeft = true;
LayerMask floorMask;
private bool grounded = false;
private enum EnemyState {
walking,
falling,
dead
}
private EnemyState state = EnemyState.falling;
// Use this for initialization
void Start () {
enabled = false;
fall ();
}
// Update is called once per frame
void Update () {
UpdatedEnemyPosition ();
}
void UpdatedEnemyPosition () {
if (state != EnemyState.dead) {
Vector3 pos = transform.localPosition;
Vector3 scale = transform.localScale;
if (state == EnemyState.falling) {
pos.y += velocity.y * Time.deltaTime;
velocity.y -= gravity * Time.deltaTime;
}
if (state == EnemyState.walking) {
if (isWalkingLeft) {
pos.x -= velocity.x * Time.deltaTime;
scale.x = -1;
} else {
pos.x += velocity.x * Time.deltaTime;
scale.x = 1;
}
}
if (velocity.y <= 0)
pos = CheckGround (pos);
transform.localPosition = pos;
transform.localScale = scale;
}
}
Vector3 CheckGround (Vector3 pos) {
Vector2 originLeft = new Vector2 (pos.x - 0.5f + 0.2f, pos.y - .05f);
Vector2 originMiddle = new Vector2 (pos.x, pos.y - .5f);
Vector2 originRight = new Vector2 (pos.x + 0.5f + 0.2f, pos.y - .05f);
RaycastHit2D groundLeft = Physics2D.Raycast (originLeft, Vector2.down, velocity.y * Time.deltaTime, floorMask);
RaycastHit2D groundMiddle = Physics2D.Raycast (originMiddle, Vector2.down, velocity.y * Time.deltaTime, floorMask);
RaycastHit2D groundRight = Physics2D.Raycast (originRight, Vector2.down, velocity.y * Time.deltaTime, floorMask);
if (groundLeft.collider != null || groundMiddle.collider != null || groundRight.collider != null) {
RaycastHit2D hitRay = groundLeft;
if (groundLeft) {
hitRay = groundLeft;
} else if (groundMiddle) {
hitRay = groundMiddle;
} else if (groundRight) {
hitRay = groundRight;
}
pos.y = hitRay.collider.bounds.center.y + hitRay.collider.bounds.size.y / 2 + .5f;
grounded = true;
velocity.y = 0;
state = EnemyState.walking;
} else {
if (state != EnemyState.falling) {
fall ();
}
}
}
void OnBecameVisible () {
enabled = true;
}
void fall () {
velocity.y = 0;
state = EnemyState.falling;
grounded = false;
}
}marioSun, 13 Dec 2015 01:36:06 GMTvespa39i am having issues with my mario clone projecthttp://answers.unity.com/questions/1108323/i-am-having-issues-with-my-mario-clone-project.html
here is my Mario Clone script that i am doing for my class: if someone can help me with this i would really appreciate it thanks in advance. i have redone this many times - thinking i am missing something from my teachers video - but i keep getting the same error,, any reasons why this would happen?
public class Camerafollow : MonoBehaviour {
public Transform target;
public Transform leftBounds;
public Transform rightBounds;
public float smoothDampTime = 0.15f;
private Vector3 smoothDampVelocity = Vector3.zero;
private float camWidth, camHeight, levelMinX, levelMaxX;
// Use this for initialization
void Start () {
camHeight = Camera.main.orthographicSize * 2;
camWidth = camHeight * Camera.main.aspect;
float leftBoundsWidth = leftBounds.GetComponentInChildren<SpriteRenderer>().bounds.size.x / 2;
float rightBoundsWidth = rightBounds.GetComponentInChildren<SpriteRenderer>().bounds.size.x / 2;
levelMinX = leftBounds.position.x + leftBoundsWidth + (camWidth/2);
levelMaxX = rightBounds.position.x - rightBoundsWidth - (camWidth/2);
}
// Update is called once per frame
void Update () {
if (target) {
float targetX = Mathf.Max(levelMinX, Mathf.Min(levelMaxX, target.position.x));
float x = Mathf.SmoothDamp(transform.position.x, targetX, ref smoothDampVelocity, smoothDampTime);
transform.position = new Vector3(x, transform.position.y, transform.position.z);
}
}
}
and here is the error messages i am getting
Assets/scripts/Camerafollow.cs(36,29): error CS1502: The best overloaded method match for `UnityEngine.Mathf.SmoothDamp(float, float, ref float, float)' has some invalid arguments
Assets/scripts/Camerafollow.cs(36,29): error CS1503: Argument `#3' cannot convert `UnityEngine.Vector3' expression to type `float'error messageclonemarioSun, 06 Dec 2015 17:48:07 GMTvespa39Camera Follow problem D:http://answers.unity.com/questions/1098212/camera-follow-problem-d.html
I've been trying to make the camera work properly for some time now and i can't find anything useful. I want to make a Super Mario-like camera follow, I'm using this code, and it's working nicely for the x position but i wanted the threshold for y to be bigger, and i already tried to make one for y and one for x, because i dont want the player to be in the center of the camera, i only want the camera to go up or down in case the player goes really really close to the borders for y position... i even tried to use the script in an object and make it follow the player and child the camera to the object and it didnt go out as planned... depending on the speed the camera stutters too so if theres somethin i can do to make it smoother please help me! so basically i need a way to limit the y movement according to the player position where the player is never on the center of the camera and something to make the camera follow smoother.
public class CameraController : MonoBehaviour
{
[SerializeField]
Transform player;
private Vector3 moveTemp;
[SerializeField]
float speed = 4;
[SerializeField]
float xDifference;
[SerializeField]
float yDifference;
[SerializeField]
float threshold = 3;
void FixedUpdate()
{
if (player.transform.position.x > transform.position.x) {
xDifference = player.transform.position.x - transform.position.x;
} else {
xDifference = transform.position.x - player.transform.position.x;
}
if (player.transform.position.y > transform.position.y) {
yDifference = player.transform.position.y - transform.position.y;
} else {
yDifference = transform.position.y - player.transform.position.y;
}
if (xDifference >= threshold || yDifference >= threshold)
{
moveTemp = player.transform.position;
moveTemp.z = -17;
transform.position = Vector3.MoveTowards(transform.position, moveTemp, speed * Time.deltaTime);
}
}
}camera movementcamera followmarioSun, 15 Nov 2015 10:01:33 GMTNikhira2D Voxel Screen - How to like this game?http://answers.unity.com/questions/1035629/2d-voxel-screen-how-to-like-this-game.html
I've never worked with voxels, but I want to make a minigame that's somewhat similar to this:
https://www.youtube.com/watch?v=8N_0B_TtPLI#t=04m53s
And I'm looking for that part with how you can simply erase part of the black screen, and making anything lying behind it becoming Renderer.isVisible.
How can I approach this?2d2d gamevoxelsmarioTue, 25 Aug 2015 20:23:40 GMTAngryCSharpNerdThird Person Platformer Controlshttp://answers.unity.com/questions/1029746/third-person-platformer-controls.html
I've posted this on the Unity3D Sub Reddit but I'm posting it here as well in hopes of finding the best solution to my problem.
Currently I have a controller setup using the SuperCharacterController asset, in my controller I use a variable corresponding to the direction my player is facing, this is based off of my mouse motion. What this means is that based on where I'm looking the left input will make my player just go directly to the left, the right to the right, etc. Here's a little clip of me controlling the player: https://imgrush.com/Kdr7Kz92gcFl , the code is based off of this: https://github.com/IronWarrior/SuperCharacterController/blob/master/Assets/Scripts/PlayerMachine.cs#L49
What I'm trying to accomplish however is something more like this: https://youtu.be/9ApibF1q86I?t=21 hold left the player will arc to the left basically making them run in a circle, hold right arc right, etc.
I had come across this video and it seems to demonstrate what I want to accomplish fairly well, https://youtu.be/b0PvJ4AWvWQ unfortunately though it's using Mecanim for all the movements from what I can tell, so it wouldn't apply to my implementation very well.
I've been experimenting trying to find a way to do this for quite some time now, and frankly I'm stuck and need help. Anything at all would be very much appreciated.cameracontrollerthird-personthird person controllermarioSun, 16 Aug 2015 15:57:36 GMTdelsys2D camera follow lock Y-Axishttp://answers.unity.com/questions/897914/2d-camera-follow-lock-y-axis.html
Hi.I am trying this script.With below script camera follows character all fine...But I want y-axis following to be locked so that i can make platformer game like mario. Please help.
using UnityEngine;
using System.Collections;
public class SmoothFollow : MonoBehaviour
{
public Transform target;
public float smoothDampTime = 0.2f;
[HideInInspector]
public new Transform transform;
public Vector3 cameraOffset;
public bool useFixedUpdate = false;
private CharacterControl _playerController;
private Vector3 _smoothDampVelocity;
void Awake()
{
transform = gameObject.transform;
_playerController = target.GetComponent<CharacterControl>();
}
void LateUpdate()
{
if( !useFixedUpdate )
updateCameraPosition();
}
void FixedUpdate()
{
if( useFixedUpdate )
updateCameraPosition();
}
void updateCameraPosition()
{
if( _playerController == null )
{
transform.position = Vector3.SmoothDamp( transform.position, target.position - cameraOffset, ref _smoothDampVelocity, smoothDampTime );
return;
}
if( _playerController.velocity.x > 0 )
{
transform.position = Vector3.SmoothDamp( transform.position, target.position - cameraOffset, ref _smoothDampVelocity, smoothDampTime );
}
else
{
var leftOffset = cameraOffset;
leftOffset.x *= -1;
transform.position = Vector3.SmoothDamp( transform.position, target.position - leftOffset, ref _smoothDampVelocity, smoothDampTime );
}
}
}platformersmoothfollowmarioTue, 10 Feb 2015 09:42:44 GMTSuraj.SMB Power Up Animation - Player Position Issuehttp://answers.unity.com/questions/890699/smb-power-up-animation-player-position-issue.html
Hi everyone,
I'm replicating the Power Up animation from the original Super Mario Bros., and I'm having a little trouble with the positioning of the player. I'm using the built-in Mechanim animation system. In the animation, the player's sprite changes quickly between Small Mario and a bigger Mario (not quite Big Mario). If I don't modify the position of the player at all, I get this:
![alt text][1]
As you can see, the player's sprite is larger than his collider, so he goes through the ground. The Y position of the player here is 0. I've moved the player up by half his height (0.08) so he appears on the ground when he's the bigger Mario, and this is the result:
![alt text][2]
[1]: /storage/temp/39909-screenshot-636.png
[2]: /storage/temp/39910-screenshot-637.png
That looks great. However, the problem occurs DURING the animation. The player moves from a Y position of 0.08 to 0 over a time span of 0.2 seconds. After those 0.2 seconds, his sprite will change back to small Mario, and the animation will repeat. As we know, the Mechanim system will gradually move the player from 0.08 to 0 over those 0.2 seconds. This means that, during the animation, the player will be bigger Mario and will be positioned below the blocks.
So I suppose my question is this: Is there any way to disable the gradual change of the Mechanim system for a particular animation? If I can do that, the player will be positioned correctly on the ground throughout the animation.
Or is there a different way I can approach this whole thing?
Thanks in advance for any help!animationpositionpowerupmariosuperSun, 01 Feb 2015 08:05:02 GMTadeeb1mario like cannonhttp://answers.unity.com/questions/878520/mario-like-cannon.html
Hi I wanted to make cannon like in Mario Bros.
Right now it shoots bullets. I have 4-second looped animation so the bullet restarts in the cannon efter hitting the wall. So here comes the problem, bullet can either hit me and be destroyed or go through me, hit the wall and restart in cannon. I want it to hit me and then restart in the cannon.
My code so far:
#pragma strict
var bullet : GameObject;
var effect : Transform;
function OnTriggerEnter ()
{
Destroy(bullet);
Instantiate(effect, transform.position, transform.rotation);
}
function Update () {
}triggerbulletcannonmarioSat, 17 Jan 2015 13:56:47 GMTadammo123NEWBIE - how to make move like a mario brothershttp://answers.unity.com/questions/789242/newbie-how-to-make-move-like-a-mario-brothers.html
Hello,
I'm new. Can someone help me write a script that my character can pass through the edges of the screen?
I write only script for teleport but i don;t need teleports.
using UnityEngine;
using System.Collections;
public class teleport1 : MonoBehaviour {
public Transform target;
void OnTriggerEnter(Collider col){
if (col.tag == "Player"){
if (transform.position.x < 0)
col.gameObject.transform.position = new Vector3(transform.position.x+2.6f, transform.position.y-0.15f);
else
col.gameObject.transform.position = new Vector3(transform.position.x-2.6f, transform.position.y-0.15f);
}
}
}
![alt text][1]
[1]: http://199.101.98.242/media/shots/56188-Mario_Bros._(World)-4.jpg
I hope someone will help
greetingsmovementteleportwalkmarioFri, 12 Sep 2014 09:42:55 GMTbararcharacter gets out of the windowhttp://answers.unity.com/questions/758747/character-gets-out-of-the-window.html
Hey guys i m new to unity and been using it for sometime so i'l be precise,i've a character,(its just a cube for now actually),and i ve used the following code to move it around the window,
using UnityEngine;
using System.Collections;
public class sphere : MonoBehaviour {
float playertime =1f;
// Use this for initialization
void Start () {
transform.position = new Vector3 (4, 0, 0);
}
// Update is called once per frame
void Update () {
transform.Translate (Vector3.right * Input.GetAxis ("Horizontal")*playertime *Time.deltaTime);
transform.Translate (Vector3.up * Input.GetAxis ("Vertical")*playertime *Time.deltaTime);
}
but the problem is
1)that the cube can get out of the window as the user keeps on pressing the keys so how can you confide the cube/character within the window,no matter how much the keys are pressed the cube never gets out of the window?
2)the next question is that-ii know about the (application.loadlevel)and can load a new level whenever a collsion happens but lets say the collision doesnt happen and the enemies are approaching from the right and the cube/character doesnt collide with the enemies and escapes by jumping and reaches to the end right of the current scene and now as soon as the cube(lets say its similar to mario )is moved forward a new scene has to load and also when the cube returns back the previous scene has to load in the same manner(eg if 2 enemes were destroyed then they should be destroyed not just load the previous scene from beginning.)
so what would the code be like?
help would be really appreciable guys,please :)collisionmovewindowmarioTue, 29 Jul 2014 05:48:49 GMTChandler221Mario Galaxy -ish controls problemhttp://answers.unity.com/questions/751837/mario-galaxy-ish-controls-problem.html
Hi there!
I am prototyping a Mario Galaxy style ("faux") gravity system. While the attraction force didn't give me much trouble, the controls are giving me a headache.
You can move. You can jump. But when you do both things simultaneously, everything goes whack.
This is my bare-bones code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
private float moveSpeed = 15;
private Vector3 moveDirection;
void Start() {
}
void Update() {
moveDirection = new Vector3(Input.GetAxisRaw("Horizontal"),0,Input.GetAxisRaw("Vertical")).normalized;
}
void FixedUpdate() {
rigidbody.MovePosition (rigidbody.position + transform.TransformDirection (moveDirection) * moveSpeed * Time.deltaTime);
}
void OnCollisionStay (Collision col)
{
if (Input.GetKeyDown (KeyCode.Space))
rigidbody.velocity += transform.up * 20;
}
}
Any leads?
Thanks a lot in advance!rigidbodygravitymariosphericalfauxgravityFri, 18 Jul 2014 23:29:12 GMTDevonOrxiI'm trying to translate this code to work for touch deviceshttp://answers.unity.com/questions/729612/im-trying-to-translate-this-code-to-work-for-touch.html
Hello, i'm trying to make this code below work for touch input (iOS specifically), it's a code for characters to move in a Mario Galaxy style, it works perfectly on Keyboard input, but i'm looking for a code similar or a way to make work on Touch.
I've been trying to think of a way to make it work but haven't hit any solutions.
Thank You.
var moveSpeed: float = 6; // move speed
var turnSpeed: float = 90; // turning speed (degrees/second)
var lerpSpeed: float = 10; // smoothing speed
var gravity: float = 10; // gravity acceleration
var isGrounded: boolean;
var deltaGround: float = 0.2; // character is grounded up to this distance
var jumpSpeed: float = 10; // vertical jump initial speed
var jumpRange: float = 10; // range to detect target wall
var robCollider = gameObject.GetComponent(CapsuleCollider);
private var surfaceNormal: Vector3; // current surface normal
private var myNormal: Vector3; // character normal
private var distGround: float; // distance from character position to ground
private var jumping = false; // flag &quot;I'm jumping to wall&quot;
private var vertSpeed: float = 0; // vertical jump current speed
function Start(){
myNormal = transform.up; // normal starts as character up direction
rigidbody.freezeRotation = true; // disable physics rotation
// distance from transform.position to ground
distGround = collider.bounds.extents.y - robCollider.center.y;
}
function FixedUpdate(){
// apply constant weight force according to character normal:
rigidbody.AddForce(-gravity*rigidbody.mass*myNormal);
}
function Update(){
// jump code - jump to wall or simple jump
if (jumping) return; // abort Update while jumping to a wall
var ray: Ray;
var hit: RaycastHit;
if (Input.GetButtonDown("Jump")){ // jump pressed:
ray = Ray(transform.position, transform.forward);
if (Physics.Raycast(ray, hit, jumpRange)){ // wall ahead?
JumpToWall(hit.point, hit.normal); // yes: jump to the wall
}
else if (isGrounded){ // no: if grounded, jump up
rigidbody.velocity += jumpSpeed * myNormal;
}
}
// movement code - turn left/right with Horizontal axis:
transform.Rotate(0, Input.GetAxis("Horizontal")*turnSpeed*Time.deltaTime, 0);
// update surface normal and isGrounded:
ray = Ray(transform.position, -myNormal); // cast ray downwards
if (Physics.Raycast(ray, hit)){ // use it to update myNormal and isGrounded
isGrounded = hit.distance <= distGround + deltaGround;
surfaceNormal = hit.normal;
}
else {
isGrounded = false;
// assume usual ground normal to avoid "falling forever"
surfaceNormal = Vector3.up;
}
myNormal = Vector3.Lerp(myNormal, surfaceNormal, lerpSpeed*Time.deltaTime);
// find forward direction with new myNormal:
var myForward = Vector3.Cross(transform.right, myNormal);
// align character to the new myNormal while keeping the forward direction:
var targetRot = Quaternion.LookRotation(myForward, myNormal);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRot, lerpSpeed*Time.deltaTime);
// move the character forth/back with Vertical axis:
transform.Translate(0, 0, Input.GetAxis("Vertical")*moveSpeed*Time.deltaTime);
}
function JumpToWall(point: Vector3, normal: Vector3){
// jump to wall
jumping = true; // signal it's jumping to wall
rigidbody.isKinematic = true; // disable physics while jumping
var orgPos = transform.position;
var orgRot = transform.rotation;
var dstPos = point + normal * (distGround + 0.5); // will jump to 0.5 above wall
var myForward = Vector3.Cross(transform.right, normal);
var dstRot = Quaternion.LookRotation(myForward, normal);
for (var t: float = 0.0; t < 1.0; ){
t += Time.deltaTime;
transform.position = Vector3.Lerp(orgPos, dstPos, t);
transform.rotation = Quaternion.Slerp(orgRot, dstRot, t);
yield; // return here next frame
}
myNormal = normal; // update myNormal
rigidbody.isKinematic = false; // enable physics
jumping = false; // jumping to wall finished
}iosrigidbodyinputtouchmarioWed, 18 Jun 2014 05:25:40 GMTKennethVeddergravity in 2d/3d mario galaxyhttp://answers.unity.com/questions/708140/gravity-in-2d3d-mario-galaxy.html
**Hello**
I need help for this project because I want to make the character move between planets like mario galaxy 2d but my project is in 2d/3d and managed to do that walk eh but you may have to walk a gravity planets and 2d jump on enemies and also to do so, I leave my idea and my source code I hope you can help me thanks
![alt text][1]
[1]: http://i1283.photobucket.com/albums/a553/Ohhleal/Captura1_zpsb0b2abcb.png
#pragma strict
enum playerStates {Idle , Walking , Running , Stopping , Sliding , Jumping , Falling , Gliding , Boosting , WallSlide, Climbing, Dead, Hit, Attack}
var player_graphic_pointer : Transform;
var player_can_move : boolean = true; // if false then the player can't move (for cutscenes etc.)
var hold_button_to_run : boolean = false; // if true then you have to hold a button to get into the run mode
var max_walking_speed : float = 6; // the maximal speed we can walk and/or switch to running
var max_running_speed : float = 8; // the maximal running speed
var gain_move_speed : float = 12; // how fast will we get to the maximum?
var lose_move_speed : float=13; // how fast will we lose the speed if we won't press a button
var stopping_lose_move_speed : float=15; // how quick do we stop if we are going against movement direction?
var x_axis_name : String = "Horizontal"; // the buttons and/or controller-analogstick for left&right. use this to make a multiplayer game
var y_axis_name : String = "Vertical";
var run_button_name : String = "Fire2";
var current_speed : float = 0; // this is our calculated speed, the velocity of the rigidbody can get in the way
private var max_speed : float = 0; // internal max speed for looking the speed
var current_mode : playerStates = playerStates.Idle; // the current and start mode we're in
var movement_direction : int = 1; // the last direction we moved
private var wall_left : boolean = false; // is a wall left from us?
private var wall_right : boolean = false; // is a wall right from us?
private var last_max_speed : float = 0; // needed to slowly decrease the max_speed
var last_velocity : Vector3; // for now a workaround for the stuck-in-wall problem
var animation_2d_component : Animation2D; // the 2danimation component we will use
var animation_3d_component : Animation3D; // the 3danimation component we will use
private var use_3d_animation : boolean = false;
var boost_graphic : Transform; // if assigned this will be spawned in the player if we extra boost
private var boost_pointer : Transform;
var can_extra_boost : boolean = true;
var time_till_boost : float = 3;
var max_boost_speed : float = 12;
private var boost_count_down : float = 0;
var animation_idle : String = "Idle";
var animation_walk : String = "Walk";
var animation_run : String = "Run";
var animation_slide : String = "Slide";
var animation_runslide : String = "RunSlide";
var animation_stop : String = "Stop";
var animation_boost : String = "Boost";
var animation_goal : String = "Goal";
var use_mobile_input : boolean = false;
var mobile_joystick : Joystick;
var mobile_run : Joystick;
function play_animation(name : String)
{
if(use_3d_animation)
{
animation_3d_component.play_animation(name);
}
else
{
animation_2d_component.play_animation(name);
}
}
function return_ani_ID(name : String)
{
if(use_3d_animation)
{
return animation_3d_component.return_ani_ID(name);
}
else
{
return animation_2d_component.return_ani_ID(name);
}
}
function current_animation() : int
{
if(use_3d_animation)
{
return animation_3d_component.current_animation;
}
else
{
return animation_2d_component.current_animation;
}
}
function AniisPlaying()
{
if(use_3d_animation)
{
return animation_3d_component.character_pointer.animation.isPlaying;
}
else
{
return animation_2d_component.isPlaying();
}
}
function Start()
{
rigidbody.sleepVelocity = 0; // a good player never sleeps!
tag = "Player"; // WE are the player, okaaaay?!
if(GetComponent(Animation2D))
{
animation_2d_component = GetComponent(Animation2D) as Animation2D; // get the animation component
}
if(GetComponent(Animation3D))
{
use_3d_animation=true;
animation_3d_component = GetComponent(Animation3D) as Animation3D; // get the animation component
}
if(!player_graphic_pointer) // no graphic plane? then we must be the graphic plane!
player_graphic_pointer=transform;
}
//// this functions returns the correct button that is needed right now. this is needed for mobile versions of the game. if use_mobile_input is true, it will return the mobile inputs ////////
function return_real_axis() : Vector2
{
if(use_mobile_input)
{
return mobile_joystick.position;
}
else
{
return Vector2(Input.GetAxis(x_axis_name),Input.GetAxis(y_axis_name));
}
}
function return_real_run() : boolean
{
if(use_mobile_input)
{
return mobile_run.IsFingerDown();
}
else
{
return Input.GetButton(run_button_name);
}
}
///////////////////////////////////////////////
function FixedUpdate () {
if(!player_can_move)return;
last_velocity = rigidbody.velocity;
if(boost_pointer)
{
if(current_mode!=playerStates.Boosting)
{
Destroy(boost_pointer.gameObject);
}
}
if(current_mode==playerStates.Hit && !AniisPlaying())
{
current_mode=playerStates.Idle;
play_animation(animation_idle);
}
if(current_mode==playerStates.Jumping|| current_mode==playerStates.Falling || current_mode==playerStates.Gliding || current_mode==playerStates.WallSlide || current_mode==playerStates.Climbing || current_mode==playerStates.Hit) // in some cases, we can't use our movement code
return;
if((current_mode==playerStates.Walking) || (current_mode==playerStates.Running) || (current_mode==playerStates.Boosting)) // check the direction we are moving
{
if(return_real_axis().x!=0.0)
{
if(Mathf.Sign(return_real_axis().x)!=movement_direction) // we changed the direction while walking, let's stop
{
current_mode=playerStates.Stopping;
play_animation(animation_stop);
}
movement_direction = Mathf.Sign(return_real_axis().x); // -1 = left; 1 = right;
if(current_mode!=playerStates.Jumping && current_mode!=playerStates.Falling) player_graphic_pointer.eulerAngles.y=90*movement_direction;
}
}
if((Mathf.Abs(return_real_axis().x)<0.01 || !player_can_move) && current_mode!=playerStates.Idle && current_mode!=playerStates.Stopping && current_mode!=playerStates.Sliding) // no joystick input? then idle
{
current_mode=playerStates.Idle;
play_animation(animation_idle);
last_max_speed=0;
}
if(current_mode==playerStates.Stopping) // we are stopping
{
if(Mathf.Sign(return_real_axis().x)==movement_direction && player_can_move) // we are still trying to get in the stopping direction
{
current_speed = Mathf.Max(0,current_speed-(stopping_lose_move_speed*Time.deltaTime));
}
else // if not then stop the stopping
{
current_mode=playerStates.Idle;
play_animation(animation_idle);
movement_direction = movement_direction*-1;
}
if(current_speed==0){current_mode=playerStates.Idle;play_animation(animation_idle);}
rigidbody.velocity.x = current_speed*movement_direction*-1;
return;
}
if(current_mode==playerStates.Sliding) // we slow down
{
if(current_speed<0.1)
{
current_mode=playerStates.Idle;
play_animation(animation_idle);
}
max_speed = current_speed;
}
if(current_mode==playerStates.Idle) // if we idle, the max speed is the maximun, so we can decrease
{
if(current_speed>0.1)
{
current_mode=playerStates.Sliding;
if(current_speed<max_running_speed)
play_animation(animation_slide);
else
play_animation(animation_runslide);
}
max_speed = current_speed;
}
if(player_can_move)
{
if(current_mode==playerStates.Walking)
max_speed = max_walking_speed*Mathf.Abs(return_real_axis().x);
if(current_mode==playerStates.Running)
{
max_speed = max_running_speed*Mathf.Abs(return_real_axis().x);
if(current_speed==max_running_speed)boost_count_down-=Time.deltaTime;
else boost_count_down = time_till_boost;
if(boost_count_down<0 && can_extra_boost)
{
current_mode=playerStates.Boosting;
play_animation(animation_boost);
if(boost_graphic)
{
boost_pointer = Instantiate (boost_graphic, player_graphic_pointer.transform.position, Quaternion.identity) as Transform;
boost_pointer.transform.parent = transform;
boost_pointer.transform.position-= Vector3.forward/2;
boost_pointer.transform.eulerAngles = player_graphic_pointer.transform.eulerAngles;
}
}
if(hold_button_to_run && !return_real_run())
{
current_mode=playerStates.Walking;
play_animation(animation_walk);
}
}
if(current_mode==playerStates.Boosting)
{
max_speed = max_boost_speed*Mathf.Abs(return_real_axis().x);
}
}
if(max_speed < last_max_speed)
{
max_speed = last_max_speed - lose_move_speed*Time.deltaTime;
}
else
{
last_max_speed = max_speed;
}
if(Mathf.Abs(return_real_axis().x)>0.01 && player_can_move && (current_mode==playerStates.Idle || current_mode==playerStates.Sliding))
{
// max_speed=0;
last_max_speed=0;
current_mode=playerStates.Walking;
play_animation(animation_walk);
}
if(wall_left && movement_direction==-1)
{
current_speed =0;
}
if(wall_right && movement_direction==1)
{
current_speed = 0;
}
if(current_mode!=playerStates.Stopping)
{
if(Mathf.Abs(return_real_axis().x)>0.02)
current_speed = Mathf.Clamp(current_speed+(gain_move_speed*Time.deltaTime),max_speed*-1,max_speed);
else
{
current_speed = Mathf.Clamp(current_speed-(lose_move_speed*Time.deltaTime),0,max_speed);
}
rigidbody.velocity.x = current_speed*movement_direction;
}
if((current_speed<=max_running_speed && current_mode == playerStates.Boosting))
{
play_animation(animation_run);
current_mode=playerStates.Running;
}
if((current_speed<=max_walking_speed && current_mode == playerStates.Running))
{
play_animation(animation_walk);
current_mode=playerStates.Walking;
}
if((current_speed>=max_walking_speed && current_mode == playerStates.Walking && !hold_button_to_run) || (hold_button_to_run && return_real_run() && current_mode == playerStates.Walking && current_speed>=max_walking_speed))
{
current_mode=playerStates.Running;
play_animation(animation_run);
boost_count_down = time_till_boost; // reset the countdown
}
if(current_mode!=playerStates.Idle)
last_max_speed = max_speed;
}
function OnCollisionEnter(collisionInfo : Collision)
{
if(current_mode!=playerStates.Jumping || current_mode!=playerStates.Falling || current_mode!=playerStates.Hit || current_mode!=playerStates.Gliding || current_mode!=playerStates.WallSlide || current_mode!=playerStates.WallSlide )
{
wall_left=false;
wall_right=false;
for (var contact : ContactPoint in collisionInfo.contacts) {
Debug.DrawRay(contact.point, contact.normal * 10, Color.white);
if(GetComponent(CapsuleCollider))
{
if(transform.InverseTransformPoint(contact.point).x<-0.2)
{
wall_left=true;
transform.position.x+=0.005;
rigidbody.velocity.y = last_velocity.y;
}
if(transform.InverseTransformPoint(contact.point).x>0.2)
{
wall_right=true;
transform.position.x-=0.005;
rigidbody.velocity.y = last_velocity.y;
}
}
}
}
}
function OnCollisionStay(collisionInfo : Collision)
{
wall_left=false;
wall_right=false;
for (var contact : ContactPoint in collisionInfo.contacts) {
Debug.DrawRay(contact.point, contact.normal * 10, Color.white);
if(GetComponent(CapsuleCollider))
{
if(transform.InverseTransformPoint(contact.point).x<-0.2)
{
wall_left=true;
transform.position.x+=0.005;
}
if(transform.InverseTransformPoint(contact.point).x>0.2)
{
wall_right=true;
transform.position.x-=0.005;
}
}
}
}
function OnCollisionExit(collisionInfo : Collision)
{
wall_left=false;
wall_right=false;
}gravityplanetmarioThu, 15 May 2014 04:15:00 GMTalberto057How to change a Texture with a Delayhttp://answers.unity.com/questions/612609/how-to-change-a-texture-with-a-delay.html
I am trying to do a copy of the Mario with another character.
The problem happens when the character have velocity.x == 0 change between 2 textures but goes very fast.
I tried using "yield WaitForSeconds(1.5)" but doesn´t work.
Thanks to all of you.
I leave the code here:
function Update ()
{
velocity = Vector3(Input.GetAxis("Horizontal"), 0, 0);
if(velocity.x == 0)
{
StopCoroutine("MovIdle");
StartCoroutine("MovIdle");
}
if(velocity.x > 0)
{
Caminar();
}
}
var imagenes : Texture[];
<strong>// This is the first option that i used</strong>
function Animacion()
{
for(var img in imagenes)
{
renderer.material.SetTexture("_MainTex", img);
yield WaitForSeconds(retraso);
}
}
<strong>// This is the second option that i used</strong>
function MovIdle()
{
if(contador == 0)
{
yield WaitForSeconds(retraso);
renderer.material.SetTexture("_MainTex", imagenQuieto1);
contador++;
}
else if(contador == 1)
{
yield WaitForSeconds(retraso);
renderer.material.SetTexture("_MainTex", imagenQuieto2);
contador = 0;
}
}texturechangeyielddelaymarioThu, 09 Jan 2014 15:34:31 GMTAitorMihashiHow do I make a choice based level select screen?http://answers.unity.com/questions/590041/how-do-i-make-a-choice-based-level-select-screen.html
I am making a 2D game and need to make a level select screen; this screen will be choice based, so if you pass a level you can get a choice to follow one path to a level or another path to a different one, kind of like "Mario" or "Organ Trails".
All help will be extremely appreciated.androidpathsmariolevel selectThu, 05 Dec 2013 03:27:20 GMTPhoenixSolMaking a 2D platformer not go backwards.http://answers.unity.com/questions/527751/making-a-2d-platformer-not-go-backwards.html
Ok, I'm sure this question has been covered before, but I can't seem to find the right keywords.
I'm making a 2D platformer, and I want to make it so that the main character can't go back past the camera bounds on the left (like in Super Mario), so I put a big long collider box on the bound of the left camera. Now the enemy can't run past the left camera bound....but it also pushes all the enemies along with it. I want everything to be able to go through the collider but the player.
So, do I need to use layer based collision? The problem is, I can't seem to get the collider not to affect everything else. Any ideas?cameraplatformerbackwardsbackmarioSat, 31 Aug 2013 14:57:35 GMTCG-DJKart Racer (Mario Kart/CTR) Physicshttp://answers.unity.com/questions/453177/kart-racer-mario-kartctr-physics.html
Hello. I'm pretty new to Unity, and I'm still trying to get my head around how the physics engine works. I'm trying to create a cartoon-styled kart racing game, based on Mario Kart and/or Crash Team Racing. I've made a few attempts at this. My first one used the built-in WheelColliders, but I had serious issues getting the kart to stay upright (even when the centre of mass was as low as it could go, it was still possible for the kart to fall over). I tried a different tactic, which was to use Raycasts to align the kart to the ground, and apply the rest of the physics through the rigidbody. This didn't work either, because the physics were horribly temperamental, and caused the kart to spin off in all directions as I tried to correct it.
My third attempt is what I have at the moment, manually coding gravity and movement so that it works nicely and smoothly, and always faces the right direction. This works very well (in fact, better than the last, as I have control over the direction of gravity, which will be helpful later in the project). There is an issue with this, though. The kart can't collide with walls, and will sometimes go through the floor, because there is no collision detection. I can fix both these problems by adding a rigidbody, and fixing it's position and rotation, but then it causes an awful jittering, which makes the game virtually unplayable.
Essentially, my question is this: How could I build a racer without the realistic physics emulation built into Unity? The features I'm trying to include are:
- Kart always faces the ground
- When Kart leaves the ground, it orients vertically
- Kart can collide with walls if they are too steep
- Kart can accelerate and decelerate
- Kart can turn with a fixed degree of rotation
- Kart can skid when a button is pressed
- Kart can jump a small amount when a button is pressed
I can get most of these working, but there are always one or two that just never seem to come out right. I'm sure it's not an overly complicated engine to build, but since I'm so unfamiliar with Unity, the method for doing so always seems to escape me. I'm used to having to build everything from scratch, so this script method of programming is very jarring for me, and it makes things that should be simple just that little bit more complex.
Anyway, some help here would be most welcome. I can post what code I have if it would help.physicsraycastracingmariomario kartThu, 09 May 2013 20:33:38 GMTHoeloeEditing Character Motorhttp://answers.unity.com/questions/412817/editing-character-motor.html
Hey guys, im trying to edit the character motor so my character can only move on the X axis.
im creating a side scroller and i want to use the original charactermotor but for the life of me i cannot work out how to edit the script in such a way that it stops movement one way but not the other. does anyone have any ideas or suggestions?
what should i be looking for?
has anyone rebuilt the script for a side scroller?
Dave2dcharactercontrollersidescrollermarioFri, 08 Mar 2013 02:18:11 GMTdavidcSide Scroller Script, Need helphttp://answers.unity.com/questions/404788/side-scroller-script-need-help.html
Hey guys, Im using the basic character motor and character controller scripts but im trying to edit them in such a way that they only accept left and right motion, at the moment the game works fine, its just that if you press "up or down" the character falls off the edge. any help would be much appreciated. :)javascriptsidemarioscrollerSat, 23 Feb 2013 09:04:14 GMTdavidcMario's shader in Super Mario Galaxyhttp://answers.unity.com/questions/396177/marios-shader-in-super-mario-galaxy.html
In Super Mario Galaxy, when Mario walks behind the landscape elements, the parts of his body that are hidden show as a darkened silhouette. However, when Mario walks behind a creature, there is no darkened silhouette, it completely covers him. How did they manage to do that, and is Unity capable of something similar? Is it even a shader trick at all, or are they using multiple cameras somehow to achieve this?
I've seen many shader examples of making an object a solid color when hiding behind something else, but nothing as complex as what Mario is capable of.shadermarioSat, 09 Feb 2013 00:43:10 GMTScreenhog