how would i make my character walk around a planet like in super mario galaxy 1 or 2?
you know how when you play that game, when you walk around, you never fall off the sphere, you just keep walking around it, like if you were walking around a tiny planet? how would i do that?
i'm not really sure how to achieve this, but here are the script's i'm using for "flat" movement and jumping (and other things):
MoveAround script:
//shooting
static var UseBetterBullet = false;
var Timer : int = 0;
//dying
var ctrl : int = 100;
static var dead = false;//1st time dying
static var Dead = false;//2nd time dying
private var Respawn = true;//first respawn
static var money = 0;
static var SCORE = 0;
var constant = false;
var cont = false;
private var auto = false;
private var movement : Vector3 = Vector3.zero;
var seconds : int = 0;
var minutes : int = 0;
var hours : int = 0;
static var Player1 = true;
var bullitPrefab : Transform;
var respawn1 : Vector3;
var respawn2 : Vector3;
var RespawnToHere : Vector3;
static var DSN = false;
//geting hit
static var gotHit = false;
static var IsPlayer = true;
//respawn
function LateUpdate()
{
if(PlayerHeliPlayer.DoneFlying)
{
transform.position = RespawnToHere;
PlayerHeliPlayer.DoneFlying = false;
}
if(Dead && !Respawn)
{
transform.position = respawn2;
Dead = false;
print("i respawned yet again!");
}
if(dead && Respawn)
{//where the player respawns
transform.position = respawn1;
dead = false;
print("i respawned!");
}
}
function OnTriggerEnter( hit : Collider )
{
if(hit.gameObject.tag == "SuddenDeath1")
{
enemyFollow.MOVE1 = false;
enemyFollow.MOVE2 = true;
enemyFollow.MOVE3 = false;
}
if(hit.gameObject.tag == "SuddenDeath2")
{
enemyFollow.MOVE1 = false;
enemyFollow.MOVE2 = false;
enemyFollow.MOVE3 = true;
}
if(hit.gameObject.tag == "MoneyMaker")
{
money += 50;
Destroy(hit.gameObject);
print("I have " +money+ " Dollars!");
}
if(hit.gameObject.tag == "fallout3" && !Respawn)
{
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.
function OnGUI()
{
GUI.Label(Rect(20,100, 400,30), "Time past: " +hours+":"+minutes+":"+seconds);
}
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var Character : Transform;
private var moveDirection = movement;
function Update()
{
Timer++;
if(Timer == ctrl)
{
seconds += 1;
Timer = 0;
}
if(seconds == 60)
{
minutes += 1;
seconds = 0;
}
if(minutes == 60)
{
hours += 1;
minutes = 0;
}
if(hours == 25)
{
hours = 1;
}
if(speed < 0)
{
speed = 0;
}
if(Input.GetKeyDown(KeyCode.LeftAlt))
{
speed += 15;
}
if(Input.GetKeyDown(KeyCode.RightAlt))
{
speed -= 15;
}
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
if(auto)
{
movement = transform.forward * speed * 20 * Time.deltaTime;
print("Automatic");
}
else
{
movement = Vector3(Input.GetAxis("Horizontal"), 0,
Input.GetAxis("Vertical"));
movement = transform.TransformDirection(movement) * speed;
}
//jumping
if (Input.GetButton ("Jump")) {
movement.y = jumpSpeed;
print("I'm jumping!");
}
}
// Apply gravity
// Move the controller
controller.Move(movement * Time.deltaTime);
//main menu button
if(Input.GetKeyDown("escape"))
{
Application.LoadLevel("Main Menu");
print("Main Menu Loading...");
}
//shooting
if(Input.GetKeyDown("f"))
{
if(Input.GetKey("left shift"))
{
auto = true;
print("auto");
}
if(Input.GetKey("right shift"))
{
auto = false;
print("!auto");
}
if(!UseBetterBullet && !constant)
{
var bullit = Instantiate(bullitPrefab, gameObject.Find("spawnPoint").transform.position,
Quaternion.identity);
bullit.tag = "wormProjectile";
//shoots it forward
bullit.rigidbody.AddForce(transform.forward * 3500);
}
if(UseBetterBullet)
{
particleEmitter.emit = true;
Invoke("DestroyEmitter",1);
}
}
//prints your score
print("Score: "+SCORE);
//changes your score
switch(SCORE)
{
case 10:
Application.LoadLevel("Main Menu");
break;
}
}
function DestroyEmitter()
{
if(Time.time*1.5 > 7.5)
particleEmitter.emit = false;
}
@script RequireComponent(CharacterController)
FPS Walker script:
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
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;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
}
// 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;
}
@script RequireComponent(CharacterController)
FPFlyer script:
var speed = 6.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function FixedUpdate() {
my=moveDirection.y;
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection *= speed;
} else {
moveDirection *= speed+transform.position.y/5;
moveDirection.y=my;
}
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
// 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;
}
@script RequireComponent(CharacterController)
private var myWalker: FPSWalker=null;
var maxHeight: float=250;
function Start () {
myWalker = gameObject.GetComponent(FPSWalker);
}
function Update () {
if(Input.GetKey("delete")) {
myWalker.gravity=-20;
//myWalker.grounded=true;
} else {
myWalker.gravity=10;
}
if (transform.position.y > maxHeight) {
myWalker.gravity = 20;
}
}
@script RequireComponent(FPSWalker)
asked
Dec 05 '10 at 10:37 PM
Jesus_Freak
1.2k
●
38
●
44
●
59