[Help] C#

smoochy boys on tour

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
Hello, could someone point me in the right direction on this please....Not spent long coding in any language, but im getting somewhere using Unity3D.

Basically, i got a simple 2D game that Ascends upwards when the playerobject hits particle objects...this all works fine. Now i need to add a descending script (So that the camera stops following the player object when it starts to descend). How would i go by doing this in C#. This is all so i can run this script.

Code:
        //Update camera position if the player has climbed and if the player is too low: Set gameover.
        float currentCameraHeight = transform.position.y;
        float newHeight = Mathf.Lerp(currentCameraHeight, playerHeight, Time.deltaTime * 10);
        if (playerTrans.position.y > currentCameraHeight)
        {
            transform.position = new Vector3(transform.position.x, newHeight, transform.position.z);
        }else{
            //Player is lower..maybe below the cameras view?
            if (playerHeight < (currentCameraHeight - 10))
            {
                GameOver();
            }
        }

Basically when the player is out of camera view, the game ends, But my problem is that my camera is constantly following my player and i have no idea how to release it once the playerobject descends...Any ideas?
 

afshangrudar1

Dedicated Member
Dedicated Member
Mar 26, 2009
184
0
42
Do you mean you want it like a mario level where it only goes forward/up and if you try to go back/down you die?
 

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
Yeah i have the script for the GameOver bit, its just releasing the "Follow Player" from camera when gravity is in effect....So basically when i miss the platforms (These force velocity onto player object on collision) then i want Gravity to pull me down ... which is working , its just getting the camera to stop following the player object .. thus allowing my script to read the height variable

Code:
            if (playerHeight < (currentCameraHeight - 10))
            {
                GameOver();
 

lifco

Untrusted Member
Legendary
Golden Oldie
Loyal Member
Jul 6, 2004
3,400
66
195
UK/Italy
I made super sakes and ladders like this

I will dig out my code and gave you mate, its on dvd

Breezer you need to add me to msn
 

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
Quick example of my game lol ... its extremely basic atm and seein some performance problems when playing on the x10i (android)

HERE

Need to remodel my ship ^_^ lolll
 
Last edited:

Samuel

Mir Chronicles Dev
VIP
Feb 8, 2011
2,614
117
280
I am assuming that when the game loads both the ship and the envrionment with the same variable (lets assume its a game ticker) then adds/subtracts to/from this to move up or down.

The trick would be to seperate the ship and the environment on seperate tickers, that way you could subtract from the ship whilst adding to the envrionment...

If that makes sense? Made sense in my head :P

Sam
 

afshangrudar1

Dedicated Member
Dedicated Member
Mar 26, 2009
184
0
42
Make a var ShipYvalue and a booleon ShipHigher

In your exsiting script add code so that the camera only moves if the ShipsHigher is true. I would write a function called ShipYTest that writes the Ships Y value in to ShipYvalue variable, waits for 0.5 seconds then compares the current value with ShipYValue. If its greater then set ShipHigher to true and run your follow script, if its false then make the camera stop.

Then I would add an invisible plane that is linked to the camera and position it so its just out of view at the bottom - when the ship colides with it then show game over. OR you could test if the ship is being rendered, if not then show game over - either way is fast
 
Last edited:

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
I am assuming that when the game loads both the ship and the envrionment with the same variable (lets assume its a game ticker) then adds/subtracts to/from this to move up or down.

The trick would be to seperate the ship and the environment on seperate tickers, that way you could subtract from the ship whilst adding to the envrionment...

If that makes sense? Made sense in my head :P

Sam

My player is seperate from my environment, only thing parented with the ship is the camera and platform script (spawns randomly infront of player).

Make a var ShipYvalue and a booleon ShipHigher

In your exsiting script add code so that the camera only moves if the ShipsHigher is true. I would write a function called ShipYTest that writes the Ships Y value in to ShipYvalue variable, waits for 0.5 seconds then compares the current value with ShipYValue. If its greater then set ShipHigher to true and run your follow script, if its false then make the camera stop.

Then I would add an invisible plane that is linked to the camera and position it so its just out of view at the bottom - when the ship colides with it then show game over. OR you could test if the ship is being rendered, if not then show game over - either way is fast

Nice idea, im going to add a Fuel system in now tho .. so when that runs out it'l be gameover lol.

Thanks for the ideas guys :)
 

afshangrudar1

Dedicated Member
Dedicated Member
Mar 26, 2009
184
0
42
Ah if the Camera is parented that might be a problem - use the smooth follow script on the unify wiki
 

Breezer

Mr Mañana
Legendary
Jul 16, 2004
3,370
539
315
Aey , i know how to release the camera .... i just want an IF statement to determine the direction and velocity .. if velocity is 0 and the spaceship is moving downwards...then the camera is released, thus making my above script work ...

Anyways, ive got for a fuel system ... easier lol.
 
  • Like
Reactions: MythRohan