Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

How to fix? Character grabbing system

$
0
0
I wrote this last night, i am trying to recreate the grabbing function of the game little big planet (Those who haven't played it allows for grabbing of objects on keystroke whether it be a ball to drag around or a rope to swing from) so everything is functional besides the Hinge im trying to apply and i am not sure why, as it is the first time i've ever tried to place a hinge dynamically, any input would be massively appreciated the script will be applied to the object im trying to grab, if this is isn't enough information please let me know, i tried the source and google couldn't make sense of the source and couldn't find any legitimate guides through google so all i have left is to post and hope. Script Revision: public var IsGrabbing : boolean = false; public var CanGrab : boolean = false; public var Player : Transform; public var c : Transform; function OnTriggerEnter(Other : Collider){ if (Other.gameObject.tag == "Player"){ CanGrab = true; } } function OnCollisionEnter(c : Collision) { if (IsGrabbing == true) { var joint = gameObject.AddComponent(HingeJoint); joint.connectedBody = c.rigidbody; } } function OnTriggerExit(Other : Collider){ if (Other.gameObject.tag == "Player"){ CanGrab = false; } } function Update() { if (Input.GetKeyDown(KeyCode.G) && CanGrab == true) { IsGrabbing = true; } if (Input.GetKeyUp(KeyCode.G)) { IsGrabbing = false; } if (CanGrab == false) { IsGrabbing = false; } if (IsGrabbing == false) { Destroy (gameObject.GetComponent(HingeJoint)); } } EDIT: Thanks Chris for the pointers i will have to look into functions more as the only 3 i understand won't work for Adding the joint or at the very least i need to re examine what i'm trying to achieve Thanks wibble i was planning to restrict its movement once have some basic functionality so that will be of use in the future, i definitely still have alot to learn because i had no ideas on that matter at all. EDIT: Ok so i made some changes to the script and its somewhat functional (atleast now i know that the hinge is being placed) i believe i need to look into its constraints though because when i move my character the object doesn't, i added the revision if anyone has any additional feedback, Thanks again at the very least for the ideas on what to google and mostly for taking the time to reply.

Viewing all articles
Browse latest Browse all 7934

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>