For my Physics spell, it works pretty much like a gravity gun.
So I aim at an object and pick it up, it moves towards me and follows my wand.
The problem is it only has slight collisions with the environment. I mean like if I move the object off something slightly it will move the object along the surface, but if I just walk straight up to the wall or something, the object will just pass through it.
How could I fix this?
[QUOTE=Over-Run;44935853]For my Physics spell, it works pretty much like a gravity gun.
So I aim at an object and pick it up, it moves towards me and follows my wand.
The problem is it only has slight collisions with the environment. I mean like if I move the object off something slightly it will move the object along the surface, but if I just walk straight up to the wall or something, the object will just pass through it.
How could I fix this?[/QUOTE]
How are you moving the object? Via AddForce?
What about performing some simple spring physics? Get the displacement vector between actual position and target position, multiply by some spring factor (less than 1.0), call AddForce or set the velocity?
How exactly do you do that? Sorry I'm not the best when it comes to Physics related stuff.
Would what you said make the object move towards the wand when it hits off things or something?
[url]http://gafferongames.com/game-physics/spring-physics/[/url]
The main bit about spring physics is that in the end what you get is a force to apply to your object. You can either call AddForce, or simply add the result to your object's velocity.
Even after looking at that blog post I'm still not sure how to code it :(
Fixed my own shit C:
*Sorry for pageking.
[QUOTE=Asgard;44934031]What might be easier for you to do is place a empty game object on the position of the tank, and then place the camera inside the empty game object. Then attach the script that rotates the camera on the empty game object, and just make it rotate around with no translation. This will cause your camera to rotate and translate correctly, and the tank will always be in the bottom of the screen.[/QUOTE]
I'm sorry but I'm too stupid to understand what you mean.
I already have the camera script working but what sort of constraints should I be using between the objects and how?
[QUOTE=Over-Run;44936818]Even after looking at that blog post I'm still not sure how to code it :([/QUOTE]
Attach the moved object via a strong, strongly dampened spring to the position it should be.
This approach isn't very framerate independent though, since it lacks the situation dependent exact integration (and RK4 won't help much either I think, unless you use the true final values thereby factoring in player movement).
You can evaluate the derivations to get a higher accuracy, no idea if that's completely necessary.
Gmod doesn't do it afaik.
You could probably also just add force toward the position but you would need to take steps to reduce inertia.
New GUI is modified/based on NGUI? I wonder how much of it will be open.
Oh jeez..
I'm trying to color a player's dead body the same color they were, before they died.
[CODE]using UnityEngine;
using System.Collections;
public class PlayerHealthScript : Photon.MonoBehaviour {
private GameObject myDeadPlayer;
public int currentHealth;
public int maxHealth;
public bool dead = false;
public GameObject focusPoint;
public Vector3[] respawnPoints;
public GameObject pistol;
void Start ()
{
currentHealth = maxHealth;
}
void Update ()
{
if (currentHealth <= 0 && !dead)
{
myDeadPlayer = (GameObject)PhotonNetwork.Instantiate("DeadPlayer", transform.position, Quaternion.identity, 0);
var randomX = Random.Range (-150, 150);
var randomY = 0;
var randomZ = Random.Range (-150, 150);
var randomDir = new Vector3 (randomX, randomY, randomZ);
myDeadPlayer.rigidbody.velocity = randomDir * 1 * Time.deltaTime;
photonView.RPC ("Death", PhotonTargets.AllBuffered, null);
}
}
void OnGUI()
{
if (photonView.isMine)
{
GUI.Label(new Rect(10, 10, 150, 50), "Health: " + currentHealth);
GUI.skin.label.fontSize = 20;
}
}
[RPC]
void TakeDamage(int amt)
{
currentHealth -= amt;
}
[RPC]
void Death ()
{
dead = true;
currentHealth = 0;
gameObject.SetActive (false);
myDeadPlayer.renderer.material.color = this.renderer.material.color;
if (photonView.isMine)
{
SmoothFollowScript camScript = Camera.main.GetComponent<SmoothFollowScript> ();
camScript.target = myDeadPlayer.transform;
}
Invoke ("GetReadyToRespawn", 5);
}
void GetReadyToRespawn ()
{
photonView.RPC ("Respawn", PhotonTargets.AllBuffered, null);
}
[RPC]
void Respawn ()
{
dead = false;
currentHealth = maxHealth;
gameObject.SetActive (true);
if (photonView.isMine)
{
transform.position = respawnPoints[Random.Range(0,respawnPoints.Length)];
SmoothFollowScript camScript = Camera.main.GetComponent<SmoothFollowScript> ();
camScript.target = focusPoint.transform;
}
PistolShootingScript pistolShootingScript = pistol.GetComponent<PistolShootingScript> ();
pistolShootingScript.currentAmmo = pistolShootingScript.maxAmmo;
}
}
[/CODE]
I just simply added this.
[CODE]myDeadPlayer.renderer.material.color = this.renderer.material.color;[/CODE]
But I keep getting this error, when the player is killed.
[CODE]NullReferenceException: Object reference not set to an instance of an object
PlayerHealthScript.Death () (at Assets/Scripts/PlayerHealthScript.cs:58)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
NetworkingPeer.ExecuteRPC (ExitGames.Client.Photon.Hashtable rpcData, .PhotonPlayer sender) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1937)
NetworkingPeer.OnEvent (ExitGames.Client.Photon.EventData photonEvent) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1643)
ExitGames.Client.Photon.PeerBase.DeserializeMessageAndCallback (System.Byte[] inBuff)
ExitGames.Client.Photon.EnetPeer.DispatchIncomingCommands ()
ExitGames.Client.Photon.PhotonPeer.DispatchIncomingCommands ()
PhotonHandler.Update () (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:76)
[/CODE]
I've really tried everything, not sure what the heck is going on...
I believe it's because you added "renderer.material.color ..." line after you set the gameobject to inactive, try placing it before disabling it.
That's not it, I've tried that. I've even commented out anything related to disabling the GameObject, but I still get the error.
[QUOTE=Drury;44940426]I'm sorry but I'm too stupid to understand what you mean.
I already have the camera script working but what sort of constraints should I be using between the objects and how?[/QUOTE]
What might be a solution to your problem is to do the following:
Place an empty game object in your hierarchy, and child it to your tank. Set the empty game object's position to 0, 0, 0. After that, drag your camera into the empty game object, now also set that to position 0, 0, 0.
Your hierarchy now looks like this (hopefully):
[code]
Empty tank gameObject
- Tank graphic
- Empty game object holding camera
- Camera
[/code]
Now set the position of your camera, assuming from a top down position, to something like 0, 0, 20 or anything that places the tank almost out of view but not quite.
You can then rotate the empty game object that is holding the camera, which would cause the camera to also rotate AND keep it's 20 units of distance from your tank. No need for fancy scripts!
Thanks for the patience, it works now.
[img]http://fat.gfycat.com/DisloyalJovialArctichare.gif[/img]
[QUOTE=sarge997;44940888]Oh jeez..
...
I've really tried everything, not sure what the heck is going on...[/QUOTE]
Check both GameObjects (the one with PlayerHealthScript and myDeadPlayer) and see if they have a Renderer component attached or not.
IIRC when you use gameObject.transform, internally Unity calls GetComponent<Transform>. It should be the same for Renderer component.
You might want to remove isDead check from void Update(), as you're checking every frame whether the player has <= 0 health and dead = false. The only way for a player to die is when their health is <= 0, and for that to happen they need to receive damage. Add isDead checking in void TakeDamage(int amt) after health has been deducted. Like:
[code]
void TakeDamage(int amt)
{
if(invulnerable || dead) return;
currentHealth -= amt;
if(currentHealth <= 0)
{
dead = true;
// Instantiate deadPlayer GameObject and apply random force
// Some other stuff
}
}
[/code]
[QUOTE=secundus;44946958]Check both GameObjects (the one with PlayerHealthScript and myDeadPlayer) and see if they have a Renderer component attached or not.
IIRC when you use gameObject.transform, internally Unity calls GetComponent<Transform>. It should be the same for Renderer component.
You might want to remove isDead check from void Update(), as you're checking every frame whether the player has <= 0 health and dead = false. The only way for a player to die is when their health is <= 0, and for that to happen they need to receive damage. Add isDead checking in void TakeDamage(int amt) after health has been deducted. Like:
[code]
void TakeDamage(int amt)
{
if(invulnerable || dead) return;
currentHealth -= amt;
if(currentHealth <= 0)
{
dead = true;
// Instantiate deadPlayer GameObject and apply random force
// Some other stuff
}
}
[/code][/QUOTE]
I've actually fixed the color issue, but thanks for the tip on the health. Much appreciated!
Finally got some more time to work on NoiseLab for a bit. I ripped out the old backend which was coded badly at 2am, and replaced it with a new backend which is coded slightly less badly at 1am... But it lets me have multiple links from the same output now which is super cool.
[t]http://i.imgur.com/0FGvHDj.png[/t]
Anyone have any ideas how I can make a competent, good-feeling character controller that can work regardless of which direction "up" is?
Or how would I go about making a swept volumes controller?
[editline]1st June 2014[/editline]
Automerge?
[editline]1st June 2014[/editline]
Dealing with physics and rigidbodies is black magic sometimes. I wrote my own character controller that has great movement but was locked vertically. That was no good so I spent days trying to mess with it to get vertical movement to work, but nothing. So I copied/modified the code for unity's new standard FPS controller and it works, even though I could swear I did the same thing countless times before.
:pwn:
Edit: though the movement isn't as smooth as I would like
[editline]1st June 2014[/editline]
Is it possible to set the position of the editor camera? Or maybe use a different camera as the editor camera?
So could anybody here look over my code? I need to hand up my code soon and I really want to make sure its good enough.
[QUOTE=Unity 4.5 Changelog]New Hierarchy Window sorting - sorting of elements is now based on transform order instead of name[/QUOTE]
wtf is transform order? This is really pissing me off.
[editline]1st June 2014[/editline]
In other news, my asteroid character controller is working quite nicely.
[unity]https://dl.dropboxusercontent.com/u/13781308/Unity/Asteroid Game/Asteroid Game.unity3d[/unity]
[QUOTE=Pelf;44972609]wtf is transform order? This is really pissing me off.[/QUOTE]
What this means is that what you see in the hierarchy is the exact same order you get if you were to iterate the transforms from script.
They did this I think because in the upcoming uGUI the transform order is going to determine sort order.
[QUOTE=Pelf;44972609][...]
In other news, my asteroid character controller is working quite nicely.
[...][/QUOTE]
Why is the sun moving but not the stars?
Is this an okay way to handle changing spells in my game?
[url]http://pastebin.com/SHGNLHs0[/url]
I'm not sure if I am doing it in a bad way or not.
It's probably better to encapsulate the data defining a spell (name, sounds, colors, etc) and then define an array of those.
Is that like making a class that holds that information?
Something like:
[code]
[System.Serializable]
public class SpellInfo
{
public string SpellName;
public AudioSource SpellSound;
public Color SpellColor;
}
// ...
// in your monobehaviour class
public SpellInfo[] spells;
[/code]
Sorry, you need to Log In to post a reply to this thread.