- Home /
Moving 2D collider and lag
Just wondering what is an efficient way to have a 2D collider and animation/movement script on an object without huge lag issues, in this example I have a rotating saw blade on a sprite that moves up and down and kills the player on collision. Closest possible solution is moving the rigidbody itself but wondering if there's another simpler solution?
I am wondering same thing, in my game there are too many flying enemies and they causes a lot of lag, first of all if you have edge or polygon collider turn them into box collider(s) I did that and experienced appreciable difference (I want to make it realistic so I used multiple box collider) , but I think there is another key points but I couldn't find answer for that so I am Upvoting this question
woops, forgot about this thread since i's pretty old, found the answer myself, seems like pretty much the scenario is to move or rotate the rigidbody itself.
//Ball and chain rotation trap
private var rb2D : Rigidbody2D;
function Awake() {
rb2D = GetComponent.<Rigidbody2D>();
}
function FixedUpdate () {
rb2D.$$anonymous$$oveRotation(rb2D.rotation + (-speed*10) * Time.fixedDeltaTime);
}
or a similar situation to shoot an arrow for example
public var arrow : GameObject;
public var speed : float = 3;
function SpawnArrow () {
var arrowProjectile : GameObject = Instantiate(arrow, transform.position, transform.rotation);
arrowProjectile.GetComponent.<Rigidbody2D>().velocity =
(arrowProjectile.transform.right * speed);
}
Answer by leonalchemist · Sep 11, 2017 at 02:26 PM
Just reposting answer here to answer thread:
//Ball and chain rotation trap
private var rb2D : Rigidbody2D;
function Awake() {
rb2D = GetComponent.<Rigidbody2D>();
}
function FixedUpdate () {
rb2D.MoveRotation(rb2D.rotation + (-speed*10) * Time.fixedDeltaTime);
}
or a similar situation to shoot an arrow for example
public var arrow : GameObject;
public var speed : float = 3;
function SpawnArrow () {
var arrowProjectile : GameObject = Instantiate(arrow, transform.position, transform.rotation);
arrowProjectile.GetComponent.<Rigidbody2D>().velocity =
(arrowProjectile.transform.right * speed);
}
Your answer
Follow this Question
Related Questions
Problem with method Collider2D.isTouchingLayers() 4 Answers
Find next corner of a 2d pollygon collider 0 Answers
Using child colliders with rigidbodies/joints in 2D 0 Answers
Same script on two gameobjects, only the original(first) one is working 1 Answer
[2D] Check if 2 parts are touching in an update loop? 0 Answers