Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
hi, I just buy the ObiRope, it's so cool. i'm useing your demo GrappingHook, i use it to my little demo. please see the video.
i can attch rope from player to a object, but the object is so wired, the physic seems not right when is attched to the rope. and you can see the second
time in my video the chain and the object is all good.but the second time i don't use run time generate。
and how can i change the rope to a chain?
i think is this code?
Code: // 設置兩點的交互,rope對物體的影響在這裡設置:
var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
//var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Chain) as ObiConstraints<ObiPinConstraintsBatch>;
var batch = pinConstraints.batches[0];
batch.AddConstraint(0, character, transform.localPosition, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, hookAttachment.collider.GetComponent<ObiColliderBase>(),
hookAttachment.collider.transform.InverseTransformPoint(hookAttachment.point), Quaternion.identity);
batch.activeConstraintCount = 2;
sorry for my english, thanks.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
(29-07-2020, 02:03 AM)huahuapro Wrote: hi, I just buy the ObiRope, it's so cool. i'm useing your demo GrappingHook, i use it to my little demo. please see the video.
i can attch rope from player to a object, but the object is so wired, the physic seems not right when is attched to the rope. and you can see the second
time in my video the chain and the object is all good.but the second time i don't use run time generate。
and how can i change the rope to a chain?
i think is this code?
Code: // 設置兩點的交互,rope對物體的影響在這裡設置:
var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
//var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Chain) as ObiConstraints<ObiPinConstraintsBatch>;
var batch = pinConstraints.batches[0];
batch.AddConstraint(0, character, transform.localPosition, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, hookAttachment.collider.GetComponent<ObiColliderBase>(),
hookAttachment.collider.transform.InverseTransformPoint(hookAttachment.point), Quaternion.identity);
batch.activeConstraintCount = 2;
sorry for my english, thanks.
By default, pin constraints constrain both position and orientation. You must set the orientation compliance to a higher than zero value if you want free rotation. Each batch has an "stiffnesses" array that contains 2 * constraintCount entries: the first entry is the positional compliance, and the second one the rotational compliance. So:
Code:
Code: batch.stiffnesses[constraintIndex * 2 + 1] = 10000; // really high compliance value frees up rotation.
To create a "chain" instead of a rope, use a ObiRopeChainRenderer component, instead of a ObiRopeExtrudedRenderer. This does not affect rope physics, only the way it is rendered. See:
http://obi.virtualmethodstudio.com/tutor...modes.html
Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
it seems i'm banned? may be i'm using VPN?
so what is
in
Code: batch.stiffnesses[constraintIndex * 2 + 1] = 10000; // really high compliance value frees up rotation.
thanks.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
31-07-2020, 10:35 AM
(This post was last modified: 31-07-2020, 12:35 PM by josemendez.)
(31-07-2020, 04:33 AM)huahuapro Wrote: it seems i'm banned? may be i'm using VPN?
so what is
in
Code: batch.stiffnesses[constraintIndex * 2 + 1] = 10000; // really high compliance value frees up rotation.
thanks.
Hi there,
We haven't banned you, and your user account doesn't list as banned in the forum, so you should be able to post normally. What makes you think you might be banned? Edit: we do have anti spam filters in place, that check if you're behind VPN. This might be flagging you as a spammer, as most spammers use VPNs.
constraintIndex is the index of the constraint you want to modify. Each time you call AddConstraint(), you add a new constraint. When you want to later modify an existing constraint, you use the index of the constraint to determine what constraint to modify. 0 for the first constraint, 1 for the second constraint, 2 for the third constraint, etc.
After your code:
Code: batch.AddConstraint(0, character, transform.localPosition, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, hookAttachment.collider.GetComponent<ObiColliderBase>(),
hookAttachment.collider.transform.InverseTransformPoint(hookAttachment.point), Quaternion.identity);
You would do:
Quote:batch.stiffnesses[0 * 2 + 1] = 10000;
batch.stiffnesses[1 * 2 + 1] = 10000;
To set the compliance for both the first and the second constraint.
Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
(31-07-2020, 10:35 AM)O,thanks so much!josemendez Wrote: Hi there,
We haven't banned you, and your user account doesn't list as banned in the forum, so you should be able to post normally. What makes you think you might be banned? Edit: we do have anti spam filters in place, that check if you're behind VPN. This might be flagging you as a spammer, as most spammers use VPNs.
constraintIndex is the index of the constraint you want to modify. Each time you call AddConstraint(), you add a new constraint. When you want to later modify an existing constraint, you use the index of the constraint to determine what constraint to modify. 0 for the first constraint, 1 for the second constraint, 2 for the third constraint, etc.
After your code:
Code: batch.AddConstraint(0, character, transform.localPosition, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, hookAttachment.collider.GetComponent<ObiColliderBase>(),
hookAttachment.collider.transform.InverseTransformPoint(hookAttachment.point), Quaternion.identity);
You would do:
To set the compliance for both the first and the second constraint.
Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
I tested
Code: batch.stiffnesses[0 * 2 + 1] = 10000;
batch.stiffnesses[1 * 2 + 1] = 10000;
it seems it's not working.
do you need to see my all code? may be somthing wrong?
thanks.
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
03-08-2020, 08:31 AM
(This post was last modified: 03-08-2020, 08:31 AM by josemendez.)
(03-08-2020, 08:30 AM)huahuapro Wrote: I tested
Code: batch.stiffnesses[0 * 2 + 1] = 10000;
batch.stiffnesses[1 * 2 + 1] = 10000;
it seems it's not working.
do you need to see my all code? may be somthing wrong?
thanks.
Can you post your whole script?
Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
(03-08-2020, 08:31 AM)josemendez Wrote: Can you post your whole script?
Code: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Obi;
public class GrapplingHook : MonoBehaviour
{
public ObiSolver solver;
public ObiCollider character;
public float hookExtendRetractSpeed = 2;
public ObiRopeSection section;
public GameObject chain;
private List<GameObject> PrefabsList;
public ObiRope rope;
private ObiRopeBlueprint blueprint;
private ObiRopeExtrudedRenderer ropeRenderer;
private ObiRopeChainRenderer chainRenderer;
private ObiRopeCursor cursor;
//private Camera cam;
public RaycastHit hookAttachment;
KeyCode interKey = KeyCode.Joystick1Button0;
KeyCode addRope = KeyCode.Joystick1Button4;
KeyCode lessRope = KeyCode.Joystick1Button5;
public SpeedTutorInspectSystem.InspectionRaycast playerIns;
private bool attached = false;
private GameObject maincam;
private bool doOnce;
private SpeedTutorInspectSystem.ObjectController raycastedObj;
[SerializeField] private int rayLength = 15;
public RaycastHit hit;
void Awake()
{
//找到玩家身上的主攝像機
GameObject camobject = GameObject.FindGameObjectWithTag("MainCamera");
maincam = camobject;
//這裡學到一個超牛的,之前我沒有給chain初始化,public GameObject chain並沒有定義,下面必須初始化,否則後面的一切,update都不會觸發!
//chain = new GameObject();
PrefabsList = new List<GameObject>();
PrefabsList.Add((GameObject)Instantiate(chain, Vector3.zero, Quaternion.identity));
PrefabsList.Add((GameObject)Instantiate(chain, Vector3.zero, Quaternion.identity));
// Create both the rope and the solver:
rope = gameObject.AddComponent<ObiRope>();
chainRenderer = gameObject.AddComponent<ObiRopeChainRenderer>();
chainRenderer.linkPrefabs = PrefabsList;
chainRenderer.linkScale = new Vector3(34,34,34);
chainRenderer.twistAnchor = 0;
chainRenderer.sectionTwist = 70;
// Setup a blueprint for the rope:
blueprint = ScriptableObject.CreateInstance<ObiRopeBlueprint>();
blueprint.resolution = 0.5f;
// Tweak rope parameters:
rope.maxBending = 0.02f;
// Add a cursor to be able to change rope length:
cursor = rope.gameObject.AddComponent<ObiRopeCursor>();
cursor.cursorMu = 0;
cursor.direction = true;
}
private void OnDestroy()
{
DestroyImmediate(blueprint);
}
public void LaunchHook()
{
//這裡一定是要從攝影機發射出來的ray才行,弄了半天才找到答案!
//下面還有debugray的一種方法就是畫debug的線
Ray ray = new Ray(transform.position, maincam.transform.forward);
if (Physics.Raycast(ray, out hookAttachment))
{
//Debug.DrawLine(ray.origin, hookAttachment.point, Color.red);
StartCoroutine(AttachHook());
}
else
{
Debug.DrawLine(ray.origin, ray.origin + ray.direction*100, Color.green);
}
}
private IEnumerator AttachHook()
{
yield return 0;
Vector3 localHit = rope.transform.InverseTransformPoint(hookAttachment.point);
// 將rope由兩點畫出來:
blueprint.path.Clear();
blueprint.path.AddControlPoint(Vector3.zero, -localHit.normalized, localHit.normalized, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "Hook start");
blueprint.path.AddControlPoint(localHit, -localHit.normalized, localHit.normalized, Vector3.up, 0.1f, 0.1f, 1, 1, Color.white, "Hook end");
blueprint.path.FlushEvents();
// 畫出rope的blueprint:
yield return blueprint.Generate();
// 設置兩點的交互,rope對物體的影響在這裡設置:
var pinConstraints = blueprint.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
var batch = pinConstraints.batches[0];
batch.AddConstraint(0, character, transform.localPosition, Quaternion.identity);
batch.AddConstraint(blueprint.activeParticleCount - 1, hookAttachment.collider.GetComponent<ObiColliderBase>(),
hookAttachment.collider.transform.InverseTransformPoint(hookAttachment.point), Quaternion.identity);
batch.stiffnesses[0 * 2 + 1] = 100000000;
batch.stiffnesses[1 * 2 + 1] = 100000000;
batch.activeConstraintCount = 2;
//batch.stiffnesses[constraintIndex * 2 + 1] = 10000;
// 最終顯示出來.
rope.ropeBlueprint = blueprint;
rope.GetComponent<ObiRopeChainRenderer>().enabled = true;
}
public void DetachHook()
{
// Set the rope blueprint to null (automatically removes the previous blueprint from the solver, if any).
rope.ropeBlueprint = null;
rope.GetComponent<ObiRopeChainRenderer>().enabled = false;
}
void Update()
{
//如果用getkey的話就會一秒內按無數次,必須是Getkeydown才可以!gfg
if (Input.GetKeyDown(interKey))
{
if (!rope.isLoaded)
{
LaunchHook();
}
else
DetachHook();
}
if (rope.isLoaded)
{
if (Input.GetKey(lessRope))
{
cursor.ChangeLength(rope.restLength - hookExtendRetractSpeed * Time.deltaTime);
}
if (Input.GetKey(addRope))
{
cursor.ChangeLength(rope.restLength + hookExtendRetractSpeed * Time.deltaTime);
}
}
}
}
Posts: 6,326
Threads: 24
Joined: Jun 2017
Reputation:
400
Obi Owner:
04-08-2020, 09:43 AM
(This post was last modified: 04-08-2020, 09:43 AM by josemendez.)
Add this:
Quote:pinConstraints = rope.GetConstraintsByType(Oni.ConstraintType.Pin) as ObiConstraints<ObiPinConstraintsBatch>;
batch = pinConstraints.batches[0];
batch.stiffnesses[0 * 2 + 1] = 10000;
batch.stiffnesses[1 * 2 + 1] = 10000;
After the "rope.ropeBlueprint = blueprint;" line.
The issue is that you're setting the stiffnesses in the blueprint batch, not the actor (runtime) batch.
cheers,
Posts: 8
Threads: 2
Joined: Jul 2020
Reputation:
0
it Finally worked, thanks!
and there's a bug(belong to me), i somehow can't render the rope, i have to enable it in editor.
here's the video.
the code is still the code.
can you help me?
Thanks!
|