Not at all, I'm always happy when one of my threads turns into a meaningful discussion.ps. i hope @wonder is not mad at me that i turned his thread to a real chaos
Not at all, I'm always happy when one of my threads turns into a meaningful discussion.ps. i hope @wonder is not mad at me that i turned his thread to a real chaos
Sprites can move like vehicles. I saw in a video zombies moving in a realistic way when they turn (smooth curve, not a sharp turn), facing the direction of the move. How do you do that?
car.PhysicsBody.ApplyForce(createVector(car.ZRotation))
Sub createVector(angle As Float) As Vector
Dim rad2angle As Float = (180/cPI)*angle
Dim v As Vector
v.Initialize(Sin(rad2angle)*speed,Cos(rad2angle)*speed)
Return v
End Sub
I use also actions in SGE and I have also a FollowPath action. After seeing the list of parameters of FollowPath in SpriteKit, I added a new parameter to my function (OrientToPath) to do the same.there are 4 different followPath methods but i am not sure how they work and whats the difference between them.
Oh no. I will never do that.i am just thinking that maybe you could create an sknode that follow a specific path and then connect your car with this sknode with a spring joint. so if it moves it will move that car but on sharp curves the spring joint will give a smooth curve effect.
I use also actions in SGE and I have also a FollowPath action. After seeing the list of parameters of FollowPath in SpriteKit, I added a new parameter to my function (OrientToPath) to do the same.
Oh no. It's not the purpose of a joint. And what is the second body the joint should be connected to? There's none.
With the same velocity, a human doesn't take a bend like a tank because of its shape, mass, legs, hips, etc., and a tank doesn't turn like a car, which doesn't turn like a motorbike, etc. To reproduce these realistic moves, agents in game may have "steering behaviors" associated to a few properties (mass, size, velocity...):i think i misunderstood your question @Informatix.
after reading it several times i understand that you ask how i could move an sknode on my screen like a car where i apply force to it and then if i want to turn right left it should turn smooth?? and not how to move sknodes automatically on a path right?
so i would do it with a simple function
i would apply a force to the skspritenode physicbody according to his zrotation. (angle of the node)
so something like this:
B4X:car.PhysicsBody.ApplyForce(createVector(car.ZRotation)) Sub createVector(angle As Float) As Vector Dim rad2angle As Float = (180/cPI)*angle Dim v As Vector v.Initialize(Sin(rad2angle)*speed,Cos(rad2angle)*speed) Return v End Sub
now when i rotate the car by clicking on left/right buttons, the force is applied to the car according to his zRotation (sknode angle in radians).
although the car front in the texture needs to be on angle 0 (so pointing up)
Is a point inside a polygon:
Converted from a C routine taken from here: http://www.codeproject.com/Tips/84226/Is-a-Point-inside-a-Polygon
There is an explanation of it's workings and it's license in the link.
B4X:Private Sub pnpoly(nvert As Int, vertx() As Int, verty() As Int, testx As Int, testy As Int) As Boolean Dim i, j As Int Dim c As Boolean = False j=nvert-1 For i = 0 To nvert -1 If (((verty(i) > testy) <> (verty(j) > testy)) And (testx < (vertx(j) - vertx(i)) * (testy - verty(i)) / (verty(j) - verty(i)) + vertx(i))) Then c = Not(c) End If j=i Next Return c End Sub
Private Sub pnpoly(nvert As Int, vertx() As Int, verty() As Int, testx As Int, testy As Int)
Number of vertices. Length of vertx and verty.hi,
B4X:Private Sub pnpoly(nvert As Int, vertx() As Int, verty() As Int, testx As Int, testy As Int)
i understand that vertx() and verty() are the polygon path and tesx/testy is the point that is being checked (if its inside the polygon) BUT what is nvert As Int ??
thank you
It's the case for all functions involving two coordinate arrays for polygons.Strange. Why not use vertx.length ?
No reason, it was just a straight port of the c code.
Dim point() As Double = Array As Double(120,80)
'...
Dim polygon As List
polygon.Initialize
polygon.Add(Array As Double(0,0))
polygon.Add(Array As Double(200,10))
polygon.Add(Array As Double(180,200))
polygon.Add(Array As Double(40,140))
polygon.Add(Array As Double(0,0))
Log(pnpoly(polygon,point))
'...
Private Sub pnpoly(polygon As List, point() As Double) As Boolean
Dim i, j As Int
Dim c As Boolean = False
j = polygon.Size-1
For i = 0 To polygon.Size -1
Dim lpoint() As Double = polygon.Get(i)
Dim lpoint2() As Double = polygon.Get(j)
If (((lpoint(1) > point(1)) <> (lpoint2(1) > point(1))) And (point(0) < (lpoint2(0) - lpoint(0)) * (point(1) - lpoint(1)) / (lpoint2(1) - lpoint(1)) + lpoint(0))) Then
c = Not(c)
End If
j=i
Next
Return c
End Sub
Arrays are faster than lists and use less memory.I would use an arraylist of arrays of doubles()
Did you look at the numerous functions of the Intersector class? It contains all you need for intersection between polygons.EDIT: actually i am using this for my Power Blocks game where i create lots of polygons and i need to know if they collide with each other. with libgdx i could not solve it so i used my own function.
Arrays are faster than lists and use less memory.
Did you look at the numerous functions of the Intersector class? It contains all you need for intersection between polygons.
I miss your optimization/performance forum threads...Arrays are faster than lists and use less memory.
I miss your optimization/performance forum threads...
You remember it!! Thank you so much!!When will u have that streetfighter game finished.