//Reset the Positions of the UI Elements on both Start and Quit void Start() { if (ButtonFace != null) { if (Shadow != null) { MaxShadowOpacity = Shadow.color.a; Shadow.color = new Color(Shadow.color.r, Shadow.color.g, Shadow.color.b, 0f); } body = ButtonFace.GetComponent<Rigidbody>(); SpringJoint = ButtonFace.GetComponent<SpringJoint>(); InitialLocalPosition = ButtonFace.localPosition; pointerEvent = new PointerEventData(EventSystem.current); pointerEvent.button = PointerEventData.InputButton.Left; RaycastResult result = new RaycastResult(); result.gameObject = gameObject; pointerEvent.pointerCurrentRaycast = result; pointerEvent.pointerPress = gameObject; pointerEvent.rawPointerPress = gameObject; ButtonFace.localPosition = new Vector3(InitialLocalPosition.x, InitialLocalPosition.y, SpringJoint.connectedAnchor.z); PhysicsPosition = transform.TransformPoint(new Vector3(InitialLocalPosition.x, InitialLocalPosition.y, SpringJoint.connectedAnchor.z)); body.position = PhysicsPosition; } else { Debug.LogWarning("Ensure that you have a UI Element allotted in the Layer Transform!"); } }
static public int get_damper(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif UnityEngine.SpringJoint self = (UnityEngine.SpringJoint)checkSelf(l); pushValue(l, true); pushValue(l, self.damper); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
// Use this for initialization void Start() { sampleSpring = sample.gameObject.AddComponent<SpringJoint>(); sampleSpring.anchor = sample.transform.InverseTransformPoint(this.transform.position); sampleSpring.maxDistance = 0.01f; sampleOldDrag = sample.GetComponent<Rigidbody>().drag; }
public void AnchorTo(Vector3 location) { if (anchored) throw new System.InvalidOperationException("Trying to anchor while already anchored"); this.hook = gameObject.AddComponent<SpringJoint>(); hook.anchor = location; anchored = true; hook.maxDistance = this.linkLength; }
static public int constructor(IntPtr l) { try { UnityEngine.SpringJoint o; o=new UnityEngine.SpringJoint(); pushValue(l,true); pushValue(l,o); return 2; } catch(Exception e) { return error(l,e); } }
// Use this for initialization void Start () { spring = 50.0f; damper = 5.0f; drag = 10.0f; angularDrag = 5.0f; distance = 0.2f; attachToCenterOfMass = false; go = new GameObject("Rigidbody dragger"); springJoint = go.AddComponent<SpringJoint>(); }
void Start() { ChangeSpeedAndDirection(); Rigidbody = GetComponent<Rigidbody>(); Spring = GetComponent<SpringJoint>(); MeshRenderer = GetComponent<MeshRenderer>(); MeshRenderer.material.color = new Color( Random.value, Random.value, Random.value, 0.5f); }
static public int get_damper(IntPtr l) { try { UnityEngine.SpringJoint self = (UnityEngine.SpringJoint)checkSelf(l); pushValue(l, true); pushValue(l, self.damper); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int get_minDistance(IntPtr l) { try { UnityEngine.SpringJoint self = (UnityEngine.SpringJoint)checkSelf(l); pushValue(l, self.minDistance); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
void OnTriggerDown(GameObject o){ if( inside == true ){ //rint("YA"); sj = gameObject.AddComponent<SpringJoint>() as SpringJoint; sj.connectedBody =colInside.GetComponent<Rigidbody>(); sj.anchor = new Vector3( 0 , -1, 1); sj1 = gameObject.AddComponent<SpringJoint>() as SpringJoint; sj1.connectedBody =colInside.GetComponent<Rigidbody>(); sj1.anchor = new Vector3( 0 , 1, 1 ); } }
static public int constructor(IntPtr l) { try { UnityEngine.SpringJoint o; o = new UnityEngine.SpringJoint(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { UnityEngine.SpringJoint o; o = new UnityEngine.SpringJoint(); pushValue(l, o); return(1); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
static public int constructor(IntPtr l) { LuaDLL.lua_remove(l, 1); UnityEngine.SpringJoint o; if (matchType(l, 1)) { o = new UnityEngine.SpringJoint(); pushObject(l, o); return(1); } LuaDLL.luaL_error(l, "New object failed."); return(0); }
public static int constructor(IntPtr l) { try { UnityEngine.SpringJoint o; o=new UnityEngine.SpringJoint(); pushValue(l,o); return 1; } catch(Exception e) { LuaDLL.luaL_error(l, e.ToString()); return 0; } }
// Update is called once per frame void Update() { // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown (0)) return; Camera mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit; if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 100)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; if (!springJoint) { go = new GameObject("Rigidbody dragger"); Rigidbody body = (Rigidbody)go.AddComponent <Rigidbody>(); springJoint = (SpringJoint)go.AddComponent <SpringJoint>(); body.isKinematic = true; } Plane plane = new Plane(Vector3.back, constraintPlaneObject.transform.position); Ray ray = mainCamera.ScreenPointToRay (Input.mousePosition); float constraintPlaneDistance = 0.0f; plane.Raycast(ray, out constraintPlaneDistance); springJoint.transform.position = ray.GetPoint(constraintPlaneDistance); if (attachToCenterOfMass) { var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; springJoint.connectedBody.freezeRotation = true; StartCoroutine ("DragObject", hit.distance); }
static public int set_minDistance(IntPtr l) { try { UnityEngine.SpringJoint self = (UnityEngine.SpringJoint)checkSelf(l); float v; checkType(l, 2, out v); self.minDistance = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
//ECamMagnetType _eCamMagnetType; void Start() { //_eCamMagnetType = (ECamMagnetType)Enum.Parse(typeof(ECamMagnetType), gameObject.name.Substring("CCamMagnet-".Length)); // Obtain our type from the last part of our node name _oJointSpring = CUtility.FindOrCreateComponent(gameObject, typeof(SpringJoint)) as SpringJoint; _oJointSpring.maxDistance = 0; GetComponent<Rigidbody>().isKinematic = true; // Our bone moves the kinematic rigid body attached to the spring joint which pulls the one CCamTarget dynamic rigid body toward it Vector3 vecPosBackupL = transform.localPosition; // To properly setup a spring joint we 1) backup our current position, 2) travel to the current position of the moveable object, 3) attach the spring and 4) return to our backed up position = We will pull object toward us. if (CGame.INSTANCE._oCamTarget != null) { //###WEAK ###OPT transform.position = CGame.INSTANCE._oCamTarget.transform.position; _oJointSpring.connectedBody = CGame.INSTANCE._oCamTarget.GetComponent<Rigidbody>(); } transform.localPosition = vecPosBackupL; }
// Use this for initialization void Start() { dragObject = new GameObject("Dragger Object"); Rigidbody dragRigidBody = dragObject.AddComponent<Rigidbody>(); dragRigidBody.isKinematic = true; dragObject.transform.position = this.attachmentPoint.position; dragSpring = this.gameObject.AddComponent<SpringJoint>(); dragSpring.spring = springStiffness; dragSpring.damper = springDamper; dragSpring.anchor = this.transform.InverseTransformPoint(this.attachmentPoint.position); dragSpring.connectedBody = dragObject.GetComponent<Rigidbody>(); }
static public int set_minDistance(IntPtr l) { try { UnityEngine.SpringJoint self = (UnityEngine.SpringJoint)checkSelf(l); float v; checkType(l, 2, out v); self.minDistance = v; return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
void Awake() { _audioSource = Camera.main.GetComponent<AudioSource>(); _playerlogic = GetComponent<PlayerLogic>(); _transform = GetComponent<Transform>(); SetPosition(); _sphereCollider = GetComponent<SphereCollider>(); _lineRenderer = GetComponent<LineRenderer>(); _springJoint = GetComponent<SpringJoint>(); _meshRenderer = GetComponent<MeshRenderer>(); _material = _meshRenderer.material; _lineRenderer.SetVertexCount(2); }
static void SpringJoint_maxDistance(JSVCall vc) { if (vc.bGet) { UnityEngine.SpringJoint _this = (UnityEngine.SpringJoint)vc.csObj; var result = _this.maxDistance; JSApi.setSingle((int)JSApi.SetType.Rval, (System.Single)(result)); } else { System.Single arg0 = (System.Single)JSApi.getSingle((int)JSApi.GetType.Arg); UnityEngine.SpringJoint _this = (UnityEngine.SpringJoint)vc.csObj; _this.maxDistance = arg0; } }
public void Attach(Transform connectedBodyTransform) { this.connectedBodyTransform = connectedBodyTransform; if (!springJoint) { springJoint = (SpringJoint)this.gameObject.AddComponent <SpringJoint>(); } springJoint.anchor = this.transform.InverseTransformPoint(thisObjectConnectionTransform.position); springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = this.connectedBodyTransform.GetComponent<Rigidbody>(); }
private void Update() { // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown(0)) return; var mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit = new RaycastHit(); if ( !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin, mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100, Physics.DefaultRaycastLayers)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; if (!springJoint) { var go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent<Rigidbody>() as Rigidbody; springJoint = (SpringJoint) go.AddComponent<SpringJoint>(); body.isKinematic = true; } springJoint.transform.position = hit.point; if (attachToCenterOfMass) { var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; StartCoroutine("DragObject", hit.distance); }
private void Update() { // Make sure the user pressed the mouse down if (!Input.GetButtonDown("Fire1")) { return; } var mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit = new RaycastHit(); if ( !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin, mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100, Physics.DefaultRaycastLayers)) { return; } // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) { return; } if (!m_SpringJoint) { var go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent<Rigidbody>(); m_SpringJoint = go.AddComponent<SpringJoint>(); body.isKinematic = true; } m_SpringJoint.transform.position = hit.point; m_SpringJoint.anchor = Vector3.zero; m_SpringJoint.spring = k_Spring; m_SpringJoint.damper = k_Damper; m_SpringJoint.maxDistance = k_Distance; m_SpringJoint.connectedBody = hit.rigidbody; screenPoint = mainCamera.WorldToScreenPoint(m_SpringJoint.connectedBody.transform.position); offset = m_SpringJoint.connectedBody.transform.position - mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z)); StartCoroutine("DragObject", hit.distance); }
private void Update() { // Return if the mouse isn't clicked or control is disabled if (!Input.GetMouseButtonDown(0) || GameObject.FindWithTag("GameController").GetComponent<LevelController>().controlDisabled) { return; } var mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit = new RaycastHit(); if ( !Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition).origin, mainCamera.ScreenPointToRay(Input.mousePosition).direction, out hit, 100, Physics.DefaultRaycastLayers)) { return; } // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) { return; } if (!m_SpringJoint) { var go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent<Rigidbody>(); m_SpringJoint = go.AddComponent<SpringJoint>(); body.isKinematic = true; } m_SpringJoint.transform.position = hit.point; m_SpringJoint.anchor = Vector3.zero; m_SpringJoint.spring = k_Spring; m_SpringJoint.damper = k_Damper; m_SpringJoint.maxDistance = k_Distance; m_SpringJoint.connectedBody = hit.rigidbody; StartCoroutine("DragObject", hit.distance); }
void ConvertSpringJoint(LegacySpring joint) { var distanceRange = new FloatRange(joint.minDistance, joint.maxDistance).Sorted(); var constraint = new Constraint { ConstrainedAxes = new bool3(true), Type = ConstraintType.Linear, Min = distanceRange.Min, Max = distanceRange.Max, SpringFrequency = 1f, // ? SpringDamping = 0.1f // ? }; var jointFrameA = BodyFrame.Identity; jointFrameA.Position = joint.anchor; var connectedEntity = GetPrimaryEntity(joint.connectedBody); var isConnectedBodyConverted = joint.connectedBody == null || connectedEntity != Entity.Null; RigidTransform bFromBSource = isConnectedBodyConverted ? RigidTransform.identity : Math.DecomposeRigidBodyTransform(joint.connectedBody.transform.localToWorldMatrix); var jointFrameB = BodyFrame.Identity; jointFrameB.Position = math.mul(bFromBSource, new float4(joint.connectedAnchor, 1f)).xyz; var jointData = new PhysicsJoint { BodyAFromJoint = jointFrameA, BodyBFromJoint = jointFrameB }; jointData.SetConstraints(new FixedList128 <Constraint> { Length = 1, [0] = constraint }); m_EndJointConversionSystem.CreateJointEntity(joint, GetConstrainedBodyPair(joint), jointData); }
void CreateSpring (RaycastHit hit) { DestroySpring(); lineRenderer.SetPosition(1, hit.point); grabBox = hit.collider.gameObject; springVector = transform.position - hit.point; SpringJoint SP = gameObject.AddComponent<SpringJoint>(); springJoint = SP; springJoint.autoConfigureConnectedAnchor = false; springJoint.spring = 1000; springJoint.damper = 0; springJoint.maxDistance = springVector.magnitude; springJoint.connectedAnchor = hit.point; lineRenderer.enabled = true; playerController.OnGrabbed(grabBox); }
void Update() { if(!Input.GetMouseButtonDown(0)) return; Camera mainCamera = FindCamera(); RaycastHit hit; if(!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, maxDistance)) return; if(!hit.rigidbody || hit.rigidbody.isKinematic) return; if(!springJoint) { GameObject go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent<Rigidbody>(); body.isKinematic = true; springJoint = go.AddComponent<SpringJoint>(); } springJoint.transform.position = hit.point; if(attachToCenterOfMass) { Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; StartCoroutine(DragObject(hit.distance)); }
private void Update() { // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown(0)) return; Camera mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit; if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 1000, Layers.value)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; if (!_springJoint) { GameObject go = new GameObject("Rigidbody dragger"); go.hideFlags = HideFlags.HideInHierarchy; Rigidbody body = go.AddComponent<Rigidbody>(); _springJoint = go.AddComponent<SpringJoint>(); body.isKinematic = true; } _springJoint.transform.position = hit.point; if (AttachToCenterOfMass) { Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = _springJoint.transform.InverseTransformPoint(anchor); _springJoint.anchor = anchor; } else { _springJoint.anchor = Vector3.zero; } _springJoint.spring = Spring; _springJoint.damper = Damper; _springJoint.maxDistance = Distance; _springJoint.connectedBody = hit.rigidbody; StartCoroutine("DragObject", hit.distance); }
// Use this for initialization void Start() { exporter = GameObject.Find ("Manager").GetComponent<OctetExporter>(); data.nodeIdFrom = gameObject.GetComponent<ExportInfo>().id; sj = gameObject.GetComponent<SpringJoint>(); data.nodeIdTO = sj.connectedBody.gameObject.GetComponent<ExportInfo>().id; data.springFactor = sj.spring; data.anchorX = sj.anchor.x * transform.localScale.x; data.anchorY = sj.anchor.y * transform.localScale.y; data.anchorZ = sj.anchor.z * transform.localScale.z; data.anchorBX = sj.connectedAnchor.x * sj.connectedBody.transform.localScale.x; data.anchorBY = sj.connectedAnchor.y * sj.connectedBody.transform.localScale.y; data.anchorBZ = sj.connectedAnchor.z * sj.connectedBody.transform.localScale.z; exporter.springJoints.Add(data); }
public override void Interact(Transform interactor) { if (!isBeingCarried) { rigidbody.constraints = RigidbodyConstraints.FreezeRotation; joint = gameObject.AddComponent<SpringJoint>(); joint.autoConfigureConnectedAnchor = false; joint.connectedBody = interactor.rigidbody; joint.anchor = Vector3.zero; joint.connectedAnchor = Vector3.zero; joint.spring = 10000; joint.damper = 0; joint.maxDistance = 0; isBeingCarried = true; } else { Destroy(joint); isBeingCarried = false; rigidbody.constraints = RigidbodyConstraints.None; } }
public override void Update() { if (Input.GetMouseButtonDown(0)) { Camera camera = this.FindCamera(); RaycastHit raycastHit = default(RaycastHit); if (Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out raycastHit, (float)100)) { if (raycastHit.rigidbody && !raycastHit.rigidbody.isKinematic) { if (!this.springJoint) { GameObject gameObject = new GameObject("Rigidbody dragger"); Rigidbody rigidbody = gameObject.AddComponent<Rigidbody>() as Rigidbody; this.springJoint = gameObject.AddComponent<SpringJoint>(); rigidbody.isKinematic = true; } this.springJoint.transform.position = raycastHit.point; if (this.attachToCenterOfMass) { Vector3 vector = this.transform.TransformDirection(raycastHit.rigidbody.centerOfMass) + raycastHit.rigidbody.transform.position; vector = this.springJoint.transform.InverseTransformPoint(vector); this.springJoint.anchor = vector; } else { this.springJoint.anchor = Vector3.zero; } this.springJoint.spring = this.spring; this.springJoint.damper = this.damper; this.springJoint.maxDistance = this.distance; this.springJoint.connectedBody = raycastHit.rigidbody; this.StartCoroutine("DragObject", raycastHit.distance); } } } }
void Update() { //transform.position = new Vector3(transform.position.x, Mathf.SmoothDamp( transform.position.y, transform.position.y-0.06f, ref velocity.y, smoothTime),transform.position.z); // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown (0)) return; Camera mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit ; if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 100)) return; return ; if( hit.transform.parent==null ) { //MeshRenderer mr = hit.transform.GetComponent("MeshRenderer") as MeshRenderer ; hit.transform.renderer.enabled = false ; Destroy ( hit.transform.gameObject,0.0f ) ; } else { //MeshRenderer mr = hit.transform.GetComponent("MeshRenderer") as MeshRenderer ; //mr.isVisible = false ; hit.transform.renderer.enabled = false ; Destroy ( hit.transform.parent.gameObject ) ; } return ; //print( "DragRigidbodyCS" ); // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; /* newTransform.position = new Vector3( hit.transform.position.x,hit.transform.position.y+0.1f,2.0f) ; TweenTransform ttf = hit.transform.GetComponent<TweenTransform>() as TweenTransform ; ttf.Reset(); ttf.method = UITweener.Method.EaseIn; ttf.eventReceiver = gameObject ; //ttf.callWhenFinished = "moveEffect"; ttf.from = hit.transform ; ttf.to = newTransform ; ttf.duration = 0.50f ; ttf.Play( true ) ; return ; */ // hit.transform.gameObject // Rigidbody // hit.rigidbody //hit.transform editingTransform = hit.transform ; editingRigidbody = hit.rigidbody ; editingRigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ | RigidbodyConstraints.FreezePositionZ ; print( "DragRigidbodyCS if (!hit.rigidbody || hit.rigidbody.isKinematic)" ); if (!springJoint) { GameObject go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent ("Rigidbody") as Rigidbody; springJoint = go.AddComponent ("SpringJoint") as SpringJoint; body.isKinematic = true; } print(springJoint.transform.position); springJoint.transform.position = hit.point; if (attachToCenterOfMass) { Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; //DragObject(hit.distance); StartCoroutine ("DragObject", hit.distance); }
/// <summary> /// Read the data using the reader. /// </summary> /// <param name="reader">Reader.</param> public override object Read(ISaveGameReader reader) { UnityEngine.SpringJoint springJoint = SaveGameType.CreateComponent <UnityEngine.SpringJoint>(); ReadInto(springJoint, reader); return(springJoint); }
public void Lock() { if (cableJoint) { KAS_Shared.DebugLog("Lock(Winch) Removing spring joint"); Destroy(cableJoint); } KAS_Shared.SetPartLocalPosRotFrom(headTransform, this.part.transform, headOrgLocalPos, headOrgLocalRot); if (headState == PlugState.PlugDocked || headState == PlugState.PlugUndocked) { KAS_Shared.DebugLog("Lock(Winch) Dock connected port"); // Save control state Vessel originalVessel = this.vessel; bool is_active = (FlightGlobals.ActiveVessel == this.vessel); // Decouple and re-dock KASModulePort tmpPortModule = connectedPortInfo.module; UnplugHead(false); KAS_Shared.MoveAlignLight(tmpPortModule.part.vessel, tmpPortModule.portNode, this.part.vessel, this.headPortNode); AttachDocked(tmpPortModule, originalVessel); nodeConnectedPort = tmpPortModule; tmpPortModule.nodeConnectedPart = this.part; // Restore controls and focus if (is_active) { FlightGlobals.ForceSetActiveVessel(this.vessel); FlightInputHandler.ResumeVesselCtrlState(this.vessel); } } SetHeadToPhysic(false); this.part.mass = orgWinchMass; SetTubeRenderer(false); motorSpeed = 0; cableJoint = null; headState = PlugState.Locked; fxSndHeadLock.audio.Play(); }
public void Deploy() { KAS_Shared.DebugLog("Deploy(Winch) - Return head to original pos"); KAS_Shared.SetPartLocalPosRotFrom(headTransform, this.part.transform, headOrgLocalPos, headOrgLocalRot); SetHeadToPhysic(true); orgWinchMass = this.part.mass; float newMass = this.part.mass - headMass; if (newMass > 0) { this.part.mass = newMass; } else { KAS_Shared.DebugWarning("Deploy(Winch) - Mass of the head is greater than the winch !"); } KAS_Shared.DebugLog("Deploy(Winch) - Create spring joint"); cableJoint = this.part.gameObject.AddComponent<SpringJoint>(); cableJoint.connectedBody = headTransform.rigidbody; cableJoint.maxDistance = 0; cableJoint.minDistance = 0; cableJoint.spring = cableSpring; cableJoint.damper = cableDamper; cableJoint.breakForce = 999; cableJoint.breakTorque = 999; cableJoint.anchor = winchAnchorNode.localPosition; if (nodeConnectedPort) { KAS_Shared.DebugLog("Deploy(Winch) - Connected port detected, plug head in docked mode..."); nodeConnectedPort.nodeConnectedPart = null; PlugHead(nodeConnectedPort, PlugState.PlugDocked, alreadyDocked:true); } else { KAS_Shared.DebugLog("Deploy(Winch) - Deploy connector only..."); headState = PlugState.Deployed; } nodeConnectedPort = null; KAS_Shared.DebugLog("Deploy(Winch) - Enable tube renderer"); SetTubeRenderer(true); //KAS_Shared.DisableVesselCollision(this.part.vessel, headTransform.collider); }
static public int get_maxDistance(IntPtr l) { UnityEngine.SpringJoint o = (UnityEngine.SpringJoint)checkSelf(l); pushValue(l, o.maxDistance); return(1); }
// Creates spring joint void GrapnelAttach(RaycastHit hit) { swinging = true; sj = gameObject.AddComponent<SpringJoint>(); sj.autoConfigureConnectedAnchor = false; // Mathf.Infinity bugs with high force / velocity sj.spring = 9999999 * GetComponent<Rigidbody>().mass; sj.damper = 9999999 * GetComponent<Rigidbody>().mass; sj.breakForce = 9999999 * GetComponent<Rigidbody>().mass; sj.enableCollision = true; Vector3 pos = transform.position + (transform.forward * 1.25f); float dis = Vector3.Distance(pos, hit.point); sj.maxDistance = dis + 1; Rigidbody rig = hit.transform.GetComponent<Rigidbody>(); if (rig) { sj.connectedBody = rig; sj.connectedAnchor = hit.transform.InverseTransformPoint(hit.point); //grapnelRig = true; } else { sj.connectedAnchor = hit.point; //grapnelRig = false; } GrapnelDestroy(); }
// Update is called once per frame void Update() { //Update score var g0 = new Vector3(); g0 = transform.position; if(g0.y<10){ if(isPick){ if(!HaveBeenContited){ HaveBeenContited = true; GUIScriptLevel2.score++; } }else{ if(!HaveBeenContited){ HaveBeenContited = true; GUIScriptLevel2.score--; } } Destroy(gameObject, 5); //Destroy(this); } // Make sure the user pressed the mouse down if (!isButton1Activate()) return; Camera mainCamera = FindCamera(); // We need to actually hit an object RaycastHit hit; if (!Physics.Raycast(mainCamera.ScreenPointToRay(GUIScriptLevel2.positionCurseur), out hit, 100)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; if(hit.rigidbody == rigidbody){ audio.Play(); isPick = true; } if (!springJoint) { GameObject go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent ("Rigidbody") as Rigidbody; springJoint = (SpringJoint)go.AddComponent ("SpringJoint"); body.isKinematic = true; } springJoint.transform.position = hit.point; if (attachToCenterOfMass) { Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; StartCoroutine ("DragObject", hit.distance); }
static public int get_damper(IntPtr l) { UnityEngine.SpringJoint o = (UnityEngine.SpringJoint)checkSelf(l); pushValue(l, o.damper); return(1); }
// Use this for initialization void Start() { joint = GetComponent<SpringJoint> (); grappling = false; }
void Awake() { this.spring = this.GetComponent<SpringJoint> (); this.rbody = this.GetComponent<Rigidbody> (); this.prevVelocity = this.rbody.velocity; }
void Update() { // Make sure the user pressed the mouse down if (!Input.GetMouseButtonDown (0)) return; Camera mainCamera = FindCamera(); GameObject o = GameObject.Find("triangle_wood_a"); if(o){ //SliderScaleVaule=o.transform.localScale.x; //SliderScaleVaule=SliderScaleVaule+0.1f ; //o.transform.localScale =new Vector3(SliderScaleVaule,SliderScaleVaule,SliderScaleVaule); } // We need to actually hit an object RaycastHit hit ; if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 600)) return; // We need to hit a rigidbody that is not kinematic if (!hit.rigidbody || hit.rigidbody.isKinematic) return; GameObject particle ;//= (GameObject)Instantiate(particleZoomOut); if(hit.transform.name.StartsWith("wood")) { particle = (GameObject)Instantiate(particleZoomOut); } else{ particle = (GameObject)Instantiate(particleZoomIn); } particle.transform.position = new Vector3(0,0,5); //spawnParticle(); particle.transform.localScale =new Vector3 (0.2f,0.2f,0.2f); particle.transform.position = new Vector3(hit.transform.localPosition.x,hit.transform.localPosition.y,5) ; //.point + particle.transform.position; print("222"); print(hit.transform.name); hit.transform.rigidbody.WakeUp() ;//=false; //float xSize=hit.transform.GetComponent<MeshFilter>().mesh.bounds.size.x*hit.transform.localScale.x; print("///------"+ hit.collider.bounds.size.y ) ; //print(xSize ) ; //transform.localPosition); Vector3 screenpos=mainCamera.WorldToScreenPoint(hit.transform.position); print(screenpos); SliderScaleVaule=hit.transform.localScale.x; if(IGState.IsZoonOut) { SliderScaleVaule=SliderScaleVaule-0.05f ; } else { SliderScaleVaule=SliderScaleVaule+0.05f ; } hit.transform.localScale =new Vector3(SliderScaleVaule,SliderScaleVaule,SliderScaleVaule); tk2dAnimatedSprite _sprite = hit.transform.GetComponent<tk2dAnimatedSprite>() ; if(_sprite) { _sprite.Play(); //_sprite.playAutomatically= true ; //_sprite.Play("Clip0"); //print("_sprite.Play();"); } Vector3 screenPos = mainCamera.WorldToScreenPoint (hit.transform.position); print ("target is " + screenPos.x + " pixels from the left"); //return; if (!springJoint) { GameObject go = new GameObject("Rigidbody dragger"); Rigidbody body = go.AddComponent ("Rigidbody") as Rigidbody; springJoint = go.AddComponent ("SpringJoint") as SpringJoint; body.isKinematic = true; } print(springJoint.transform.position); springJoint.transform.position = hit.point; if (attachToCenterOfMass) { Vector3 anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position; anchor = springJoint.transform.InverseTransformPoint(anchor); springJoint.anchor = anchor; } else { springJoint.anchor = Vector3.zero; } springJoint.spring = spring; springJoint.damper = damper; springJoint.maxDistance = distance; springJoint.connectedBody = hit.rigidbody; //DragObject(hit.distance); StartCoroutine ("DragObject", hit.distance); }
/// <summary> /// Read the data into the specified value. /// </summary> /// <param name="value">Value.</param> /// <param name="reader">Reader.</param> public override void ReadInto(object value, ISaveGameReader reader) { UnityEngine.SpringJoint springJoint = (UnityEngine.SpringJoint)value; foreach (string property in reader.Properties) { switch (property) { case "spring": springJoint.spring = reader.ReadProperty <System.Single>(); break; case "damper": springJoint.damper = reader.ReadProperty <System.Single>(); break; case "minDistance": springJoint.minDistance = reader.ReadProperty <System.Single>(); break; case "maxDistance": springJoint.maxDistance = reader.ReadProperty <System.Single>(); break; case "tolerance": springJoint.tolerance = reader.ReadProperty <System.Single>(); break; case "connectedBody": if (springJoint.connectedBody == null) { springJoint.connectedBody = reader.ReadProperty <UnityEngine.Rigidbody>(); } else { reader.ReadIntoProperty <UnityEngine.Rigidbody>(springJoint.connectedBody); } break; case "axis": springJoint.axis = reader.ReadProperty <UnityEngine.Vector3>(); break; case "anchor": springJoint.anchor = reader.ReadProperty <UnityEngine.Vector3>(); break; case "connectedAnchor": springJoint.connectedAnchor = reader.ReadProperty <UnityEngine.Vector3>(); break; case "autoConfigureConnectedAnchor": springJoint.autoConfigureConnectedAnchor = reader.ReadProperty <System.Boolean>(); break; case "breakForce": springJoint.breakForce = reader.ReadProperty <System.Single>(); break; case "breakTorque": springJoint.breakTorque = reader.ReadProperty <System.Single>(); break; case "enableCollision": springJoint.enableCollision = reader.ReadProperty <System.Boolean>(); break; case "enablePreprocessing": springJoint.enablePreprocessing = reader.ReadProperty <System.Boolean>(); break; case "massScale": #if UNITY_2017_1_OR_NEWER springJoint.massScale = reader.ReadProperty <System.Single>(); #else reader.ReadProperty <System.Single>(); #endif break; case "connectedMassScale": #if UNITY_2017_1_OR_NEWER springJoint.connectedMassScale = reader.ReadProperty <System.Single>(); #else reader.ReadProperty <System.Single>(); #endif break; case "tag": springJoint.tag = reader.ReadProperty <System.String>(); break; case "name": springJoint.name = reader.ReadProperty <System.String>(); break; case "hideFlags": springJoint.hideFlags = reader.ReadProperty <UnityEngine.HideFlags>(); break; } } }