|
Post by pat19645 on Oct 18, 2016 10:18:53 GMT
This is not really a Invector question, but maybe somebody will help me. I made a spiketrap (like in basic locomotion update) all works fine, but i can't figure out how i can make the player stick on the spikes. Any help is welcome!
Regards, Pat.
|
|
|
Post by jgiroux on Oct 18, 2016 11:39:20 GMT
Hey Pat,
I assume you have a script running on your spike trap?
if so, when triggered couldn't you set your invector player as a child of the spike trap game object for a period of time using Ienumerator function, then set parent of invector to null afterwards when you want to *release* player fro spike trap.
let me know if you'd like a example script on what I mean.
|
|
|
Post by pat19645 on Oct 18, 2016 12:34:33 GMT
void OnTriggerEnter(Collider other){ if (other.gameObject.tag == "Player") { //other.transform.parent = transform; other.transform.position.Set(transform.position.x, transform.position.y, transform.position.z); other.transform.rotation.Set (transform.rotation.x, transform.rotation.y, transform.rotation.z, 0); } }
This is what i came up with after a google search, doesn't work... An example would be very nice jgiroux! Thanks for helping me!
|
|
|
Post by Invector on Oct 18, 2016 18:08:33 GMT
Just drag and drop the vSpikeTrap prefab and replace the mesh, make sure that the new one have approximately the same size as the prefab
|
|
|
Post by AwakenArt on Oct 18, 2016 21:08:11 GMT
Us melee 1.3 users don't have the vSpikeTrap yet... :'(
|
|
|
Post by pat19645 on Oct 19, 2016 7:00:01 GMT
Us melee 1.3 users don't have the vSpikeTrap yet... :'( That's why i try to make something simular, it works fine, except the stick on spike part
|
|
|
Post by jgiroux on Oct 19, 2016 13:08:05 GMT
here try this, just to get you started, ____________________________________________________________
public GameObject Player;
void OnTriggerEnter(Collider col) { if (col.transform.tag == "Player") { Player = col.transform.gameObject; col.transform.SetParent(this.transform); StartCoroutine (Impaled (2f)); //col.transform.SendMessage("ActivateRagdoll", SendMessageOptions.DontRequireReceiver); } }
IEnumerator Impaled (float Impaletime) { Player.transform.SetParent (this.transform); yield return new WaitForSeconds (Impaletime); Player.transform.SetParent (null); }
_________________________________________________________
this script snippet should be added to the actual spikes. keep in mind that adding the player as a child of transform may also change the scale of the player if your orginal game object (spikes) scale is not 1,1,1
easiest way around that is to create a empty game object with scale 1,1,1 and create a collider trigger on *that* empty game object and add script to it,
hope I am being clear. currently at work , so this code wasn't fully scripted out and is off top of my head and may need to be doublechecked for spelling errors.
|
|
|
Post by pat19645 on Oct 19, 2016 15:26:51 GMT
Thank you very much jgiroux! I will try it asap.
|
|
|
Post by pat19645 on Oct 20, 2016 14:43:26 GMT
I got it working partly, as i use a moving spike based on Invector's Pendulum, i had some probs that my player didn't stick. I was able to fix it using Rigidbody. One problem is that i can't seem to recover (former settings Rigidbody) and continue the game, but i will use that trap as a deadly trap anyway's . Thanks for the help jgiroux, i was trying this for a looong time before i came here for asking about it. Here's the code. I'm sure it can be improved. insert code here using UnityEngine; using System.Collections; using Invector; public class PlayerStickOnSpikes : MonoBehaviour { private GameObject Player; private Rigidbody RB; void Start() { Player = GameObject.Find ("Player"); RB = Player.GetComponent<Rigidbody> (); } void OnTriggerEnter(Collider col){ if (col.transform.tag == "Player") { Player = col.transform.gameObject; col.transform.SetParent(this.transform); StartCoroutine (Impaled (2f)); //col.transform.SendMessage("ActivateRagdoll", SendMessageOptions.DontRequireReceiver); } } IEnumerator Impaled (float Impaletime) { Debug.Log ("Impaled"); RigidbodyConstraints previousConstraints = RB.constraints; RB.constraints = RigidbodyConstraints.FreezePositionX | RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ; RB.useGravity = false; Player.transform.SetParent (this.transform); yield return new WaitForSeconds (Impaletime); Debug.Log ("Not Impaled"); RB.useGravity = true; RB.constraints = previousConstraints; Player.transform.SetParent (null); } }
|
|
|
Post by jgiroux on Oct 20, 2016 16:55:09 GMT
hey Pat,
im glad you were able to get it somewhat working, first thing I notice however is you don't really need the setparent (in red) part in the OnTrigger because the Ienumerator takes care of it (I had that in there like I said when I was writing it from work and forgot to remove it since we handled it with the coroutine instead (so we can have a timer) you could also try uncommenting the Activate Ragdoll, if you wanted ragdoll to be triggered(in green)
void OnTriggerEnter(Collider col){ if (col.transform.tag == "Player") { Player = col.transform.gameObject; col.transform.SetParent(this.transform); StartCoroutine (Impaled (2f)); //col.transform.SendMessage("ActivateRagdoll", SendMessageOptions.DontRequireReceiver);
to futher ask about this, what exactly are you looking to achieve. player triggers impaling and does a ragdoll, and then when a certain amount if time passes player reverts to normal (minus damage perhaps?)
|
|
|
Post by pat19645 on Oct 20, 2016 17:21:53 GMT
jgiroux, the trap is final, Player is dead, hanging on the spikes. The ragdoll worked, but i use the vObjectDamage script from invector where i can turn ragdoll on or off.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Dec 4, 2016 3:45:42 GMT
Have you tried doing other things from the spiketraps? Like Other game objects.
|
|