spiderman climbing walls

okay today i stayed home from college and martial arts class and from work and had a unity-a-thon yay!!

and i ran into some problems

-whats a good way to make a player climb a wall spider-man style?? I made a sloppy script on how to climb a ladder but i wanted to have an item that lets you climb all walls, is there a good way to do this?? i cant think of a way to detect wether or not the player is touching a wall and i really cant figure out how to make him climb it, any ideas??

-i have a if statement where inside it makes a random number, how can i make it take the random number once and then stop taking it??

function Update (){

if(dead=true){
	respawntarget=Random.Range(1,10);
	}
}

-how do i give credit for a kill to the player?? meaning how do i tell the difference between the player killing the target and the bots your competing against killing the target, and how do i decide the player has killed himself??

-how does unity rock so much?? its so well thought out and easy to use and forces me to not do the things im supposed to and i want to rot in front of my computer on unity and eat hot pockets instead of work and school, whats with that??

im starting to feel that im posting to many questions this is my 3rd post in 2 days, so hopefully you wont be hearing from me for a while :slight_smile:

One way could be to have all climbable wall in a layer and them cast a ray forward from the player, if it hits an wall and the raycasthit is less then some distance then allow your player to climb.

One way is to make a collection of numbers and then draw from that. E.g.

using UnityEngine;
using System.Collections;

public class UniqueRandomGenerator {
	private ArrayList numbers = new ArrayList();
	private int min, max;
	
	public UniqueRandomGenerator(int min, int max) {
		this.min = min;
		this.max = max;
		
		Reset();
	}
	
	public int getRandomNumber() {
		if (numbers.Count == 0)
			Reset();
			
		int index = Random.Range(0, numbers.Count);
		int randomNr = (int) numbers[index];
		numbers.RemoveAt(index);
		return randomNr;
	}
	
	public void Reset() {
		numbers.Clear();
		
		for (int i = min; i <= max; i++) {
			numbers.Add(i);	
		}
	}
}

I’m guessing from this that your ‘bullet’ are objects of they own, so you could add a property to them telling who fired them, that way you know who fired a bullet when applying the damage from it.

function Update (){

if(dead=true){
   respawntarget=Random.Range(1,10);
   }
}

in your code, making dead!=true after taking the random number would mean it would only take one until dead=true again. otherwise you could use another flag (true/false or 0/1 etc) inside that which would toggle the random number method independent of your dead variable.

There is a bug in the above code. The line saying ‘if(dead=true)’ is assigning the value true to the dead variable. For comparisons you should use the == operator. (= is the assignment operator, == the equality operator.)

So the test above should become:

function Update (){
   if( dead == true ){
	respawntarget=Random.Range(1,10);
   }
}

or even better (since dead is already a boolean):

function Update (){
   if( dead ){
	respawntarget=Random.Range(1,10);
   }
}

Thinking about that as i wrote it and still got it wrong, time to get more sleep! :roll:

At least you understood the question :slight_smile: I thought he wanted to generate unique random numbers.

i ran into some problems again with the random number thing so i just wanted to check if this what you meant

if(dead){
respawntarget=Random.Range(1,10)

dead=false



}

the problem is i have a delay before he actually respawns so the if that checks if his health is lower than 0 trips again and it is re accessed

im sure i can fix that myself but i just wanted to check if thats what you meant

and i usually remember the == thing, but i completly forgot i could just put (dead)

thanks guys

you mean in the delay when the health is re-assessed dead will be set to true again? if its actually a problem? then just have a trigger so that when he is first declared dead he cannot be declared dead again until after the respawn. Or, instead of a boolean for ‘dead’ make it a integer variable and have something like 0 = dead, 2 = alive and 1 = waiting, then do a check before the health check to see what state the player is in according to that script…