Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jesus_Freak · Sep 24, 2010 at 11:40 PM · gravityspawntornado-twins

Respawning with no gravity

enter code hereokay, i have my script for the respawn as the tornado twins showed it. and i added that script to the character prefab that came with the island in unity, and the respawn works, my player goes back to y=200 (thats where i origanlly started) but, i want my player to fall to the ground. can anyone please help me?

my script is:

var speed = 6.0; var jumpSpeed = 8.0; var gravity = 20.0; var bullitPrefab : Transform;

private var dead = false; private var moveDirection = Vector3.zero; private var grounded : boolean = false;

function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; //substract life here

}

}

function FixedUpdate() { if (grounded) { // We are grounded, so recalculate movedirection directly from axes moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

}

// Apply gravity moveDirection.y -= gravity * Time.deltaTime;

// Move the controller var controller : CharacterController = GetComponent(CharacterController); var flags = controller.Move(moveDirection * Time.deltaTime); grounded = (flags & CollisionFlags.CollidedBelow) != 0; }

function Update() { if(Input.GetButtonDown("Jump")) { var bullit = Instantiate(bullitPrefab, GameObject.Find("spawnPoint").transform.position, Quaternion.identity); bullit.rigidbody.AddForce(transform.forward * 4000);
}

}

function LateUpdate() { if(dead) { transform.position = Vector3(0,200,-50);

}

  }

 @script RequireComponent(CharacterController

)

im sorry if someone posted this question already, i couldnt find it.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Sep 24, 2010 at 11:41 PM 0
Share

hi, i made this question, and i forgot to say that when i respawn, i dont fall, but when the level starts, i fall.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Julian-Glenn · Sep 25, 2010 at 12:41 AM

Most likely the case is that when you first launch the level your character controller is not in fact resting exactly on the ground plane so gravity kicks in and the player drops to the ground. You can check this by viewing the player from the side and check the capsule for the char controller's position.

and to answer your question you can just change the +Y transform position of your respawn location. So if 200 is exactly level with the ground, then just add 50 units or so (0.250.-50) and you should be above the ground.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Oct 24, 2010 at 03:59 PM 0
Share

thank you, i fixed it, but this was helpful, now i respawn right where i started in the beginning, but now, i fall like i should.

avatar image
0
Best Answer

Answer by Jesus_Freak · Oct 25, 2010 at 01:57 AM

here's my complete move around script (Updated):

//shooting var bullitPrefab : Transform; var PlayerPrefab : Transform; //dying private var dead = false; private var Respawn = true; static var SCORE = 0;

static var DSN = false;

//geting hit static var gotHit = false; static var IsPlayer = true;

//respawn function LateUpdate() { if(DSN) {
// activates the game object. gameObject.active = true; } if(dead && !Respawn) { transform.position = Vector3(3604.086, 610.248, -1853.058); dead = false; print("i respawned yet again!"); } if(dead && Respawn) {//where the player respawns transform.position = Vector3(4664.995, 592.0738, -1793.104); dead = false; print("i respawned!"); } }

function OnTriggerEnter( hit : Collider ) { if(hit.gameObject.tag == "fallout3") { dead = true; HealthControl.LIVES -= 1; } if(hit.gameObject.tag == "fallout2") { Respawn = false; } //when the player falls off (this doesnt really work too good. ) if(hit.gameObject.tag == "fallout") { dead = true; //subtract life here HealthControl.LIVES -= 1; print("i fell off..."); }

//getting hit (this works) if(hit.gameObject.tag == "enemyProjectile") { gotHit = true; HealthControl.HITS += 1; Destroy(hit.gameObject); print("i got hit!"); } //manipulating weather if(hit.gameObject.tag == "weather") { ParticleEmitToggle.WCONTROL = true; print("Now i can control weather."); } //level select button controls if(hit.gameObject.tag == "Level2") { GUIshader.Level2 = true; print("hit level two"); }

if(hit.gameObject.tag == "Level3") { GUIshader.Level3 = true; print("hit level three"); }

if(hit.gameObject.tag == "Level4") { GUIshader.Level4 = true; print("hit level four"); }

if(hit.gameObject.tag == "Level5") { GUIshader.Level5 = true; print("hit level five"); }

if(hit.gameObject.tag == "WORK") { MovingPlatform4.work = true; } }

/// This script moves the character controller forward /// and sideways based on the arrow keys. /// It also jumps when pressing space. /// Make sure to attach a character controller to the same game object. /// It is recommended that you make only one call to Move or SimpleMove per frame.

var speed : float = 6.0; var jumpSpeed : float = 8.0; var gravity : float = 20.0;

private var moveDirection : Vector3 = Vector3.zero;

function Update() { var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { // We are grounded, so recalculate // move direction directly from axes moveDirection = Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); moveDirection = transform.TransformDirection(moveDirection); moveDirection *= speed;

//jumping if (Input.GetButton ("Jump")) { moveDirection.y = jumpSpeed; print("I'm jumping!"); } }

// Apply gravity moveDirection.y -= gravity * Time.deltaTime;

// Move the controller controller.Move(moveDirection * Time.deltaTime);

//main menu button if(Input.GetKeyDown("escape")) { Application.LoadLevel("Main Menu"); print("Main Menu Loading..."); }

//shooting if(Input.GetKeyDown("f")) {//makes a fireball prefab var bullit = Instantiate(bullitPrefab, gameObject.Find("spawnPoint").transform.position, Quaternion.identity);

 bullit.tag = "wormProjectile";
 //shoots it forward
 bullit.rigidbody.AddForce(transform.forward * 4000);
 //makes it go completely straight
 useGravity = false;
 print("I shot a fireball!");
 }

 //prints your score

print("Score: "+SCORE); //changes your score switch(SCORE) { case 10: Application.LoadLevel("Main Menu"); break; }

}

 @script RequireComponent(CharacterController

)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MayharS · Oct 30, 2010 at 01:00 AM

you didn't tell unity that ur not dead anymore after respawning, so it'll keep returning you to the desired point because of the if(dead) statement.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jesus_Freak · Oct 30, 2010 at 01:22 AM 0
Share

but didn't i put under the if(dead) statement:

dead = false; ? then that would say that i'm not dead anymore. right?

avatar image Jesus_Freak · Oct 30, 2010 at 01:25 AM 0
Share

OH!!! you were talking about my original script right? ok. well, my completed script, the one that is correct is the one in the answer before yours.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

change gravity after time 1 Answer

Trouble spawning cloned objects 1 Answer

worm game spawning incorrectly 1 Answer

A Rigidbody moving in a moving Rigidbody 0 Answers

Ramp for stairs causes player to slide down. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges