Posts: 3,522
Threads: 189
Joined: Dec 2003
I have Angle and TargetAngle
TargetAngle is relative to current X, Y position and Target X, Y
RoT (Rate of Turning) specifys how fast it can turn, namely, how many degrees
Using this, how would I go about making it always turn towards the target using the shortest possible way?
Like:
Angle = 45
Target = 270
Would mean that: Angle = Angle - Rot
But:
Angle = 135
Target = 270
Would mean that: Angle = Angle + Rot
I can't get it working, and the particles (this is for a particle engine) seems to do... whatever they like basically...
Posts: 2,771
Threads: 96
Joined: Oct 2003
I had this same problem some up when i was making AI for a top down tank deathmatch game a long time ago.
let me see if i can remember it. Ill get back to you.
EDIT
found it!
I made a visual example of it working.
[syntax="qbasic"] targetangle = 270
angle = 45
DO
tang = targetangle
tang = tang - angle
IF tang > 360 THEN tang = tang - 360
IF tang < 0 THEN tang = tang + 360
IF tang < 180 THEN
angle = angle + 1
if angle > 360 then angle = angle - 360
ELSE
angle = angle - 1
if angle < 0 then angle = angle + 360
END IF
PRINT angle
LOOP[/syntax]
Posts: 480
Threads: 24
Joined: Mar 2003
Check my 2d node sim I've got functions for what you're looking for in there.
Posts: 3,522
Threads: 189
Joined: Dec 2003
I've tried your code Meg, gives the same result as Darks...
Thumbnail, 640x480:
The particles are moving outwards, theyr supposed to move towards the small cross.
They all start in cente, with random angle (they gorm a perfect cirle as there are so many of them) then after a cetain distance they split up, and move away like on the pic. Never to return *sniffle*
Posts: 480
Threads: 24
Joined: Mar 2003
I'm not sure what the code you're looking for is, but with the node sim, it works like this:
1. create two nodes:
Code: Set NodeToCreate%, xloc!, yloc!, xvelocity!, yvelocity!
2. point one node at the other
Code: PointAt NodeToTarget%, NodeThatIsTargetting%
3. boost one node
Code: Boost NodeToBoost%, boostpower!
You can also rotate a node by angle A%:
Code: Rotate NodeToRotate%, A%
The Theta!(n1%, n2%) function in the node sim returns the angle that node n1% would have to rotate off the x-axis (angle 0) in order to be pointing at node n2%. For example, if node 2 were directly to the left of node 1, Theta!(n1%, n2%) would return Pi (radian equivalent to 180 degrees).
*peace*
Meg.
Posts: 3,522
Threads: 189
Joined: Dec 2003
Look at the screenshot.
Particles are forming two "beams" then move away from the target at certain angles.
Posts: 480
Threads: 24
Joined: Mar 2003
I can't really help more without looking through the code. All I know is if you put the following into the Node Sim:
Code: 'create node 1 at the origin
Set 1, 0, 0, 0, 0
'create node 2 at (100, 100)
Set 2, 100, 100, 0, 0
'create node 3 at (-100, -100)
Set 3, -100, -100, 0, 0
'point both nodes 2 and 3 at node 1.
PointAt 1, 2
PointAt 1, 3
'boost both nodes 2 and 3 towards node 1.
Boost 2, .5
Boost 3, .5
it moves them inward, not outward.
Posts: 3,522
Threads: 189
Joined: Dec 2003
Ya, it seems to be a FB problem.
Darks code works in QB, but produces the eaxct same problem i have once moved to FB.
Going through all code again now.
Posts: 3,288
Threads: 167
Joined: Nov 2001
Liked your demo z!re! Very cool!!!
hey why not do this:
let's say you have a vector type that has float values as it's components:
Code: dim v as vector
v.x = mouse.x - part.x
v.y = mouse.y - part.y
since SQR is a lil slow...
dim angle as single
Code: angle = atan2(v.y, v.x)
v.x = cos(angle) * speed
v.y = sin(angle) * speed
Code: part.x = part.x + v.x
part.y = part.y + v.y
To simulate real homing you should save he old angle, compare it to newangle and increment or decrement your current angle.
If you wan't a faster one, I have one at home which Mono and Disco used (Sub Blobs) that used no ATAN2, so trig funks, just multiply and add so it's very fast and works like the homing missile you see in Raiden Trad. :*)
Posts: 3,522
Threads: 189
Joined: Dec 2003
Thanks, the demo isnt relly a demo, just a cut down version of the MOoEngine, working to get a walkaround/spellcasting/audio/weather-fx/lightning demo out, prolly be a while though
Back to topic:
That is what I'm trying to do... but they dont home in, well, they do, except for in the corners, where they're just repelled.
All of he people who have looked at the code say it should work by all means, the QB version works. But once in FB it does not.
Like I said, going over all of the code to see where the coding-error or FB bug is.
And angle is never calculated, it is stored i neach particle, and then I use it to get vx and vy, faster than having vx, vy, transforming to angle, transforming back to vx, vy
|