Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-01-2005 13:06
I am getting an error message in this script. The script is supposed to make a prim orbit a center point. float i = 0; float diameter = .10; default { state_entry() { llTargetOmega(<0,0,1>, 0.1, 1); llSetTimerEvent(.5); } timer() { i = i + .025; i = (float)i % (float)TWO_PI; llSetPos(llGetPos() + <llCos(i) * diameter, llSin(i) * diameter, 0>  ; } } The problem is I get this error: (14, 30) : Error : Type mismatch If I do another kind of operator like + or * it works fine. It just doesn't like that I am trying to mod a number by TWO_PI. Any Thoughts?
|
Kali Dougall
Purple and Spikey
Join date: 5 Feb 2005
Posts: 98
|
05-01-2005 13:24
The modulo is, by definition, only an integer operation. It finds the remainder of two integers... i.e., 11 / 3 is 3 with a remainder of 2. So 11 % 3 = 2. It's often used to find even numbers, because if X is even, then X % 2 = 0, but if it's odd, X % 2 = 1. My point here is that such an operation is fundamentally incompatible with floating points. Thus the type mismatch error.
So the question becomes, what exactly are you trying to accomplish on the line where you've used the modulo?
|
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-01-2005 13:34
Well as with cos once you get to 2*PI you are basically back were you started. If you where looking at a graph of cos(x). So I just didn't want i to get infanantly large. I guess I could just do
if(i > TWO_PI) i = 0;
Instead of doing
i %= TWO_PI:
But thanks for telling me what you did. That way I can move on to other things.
|
Danny DeGroot
Sub-legendary
Join date: 7 Jul 2004
Posts: 191
|
05-01-2005 14:21
Hi Hiro,
I don't know if you've thought of this approach and discarded it, but here's something else that might work:
- rez a very small prim (say, a sphere or a cylinder flattened to a disk).
- set your orbiting object in the same plane as the new prim, and at a distance from it equal to your desired orbital radius. Then, link it to the new prim, selecting the new prim last of all. Since the new prim is now the root prim of the linkset, its coordinates will become the coordinates for the entire set.
- center the tiny prim inside your base object, and then apply llTargetOmega() to a script in the root prim. The root prim will act as the center of rotation.
== danny d.
|
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
|
05-01-2005 14:25
From: Hiro Turnbull Well as with cos once you get to 2*PI you are basically back were you started. If you where looking at a graph of cos(x). So I just didn't want i to get infanantly large. I guess I could just do
if(i > TWO_PI) i = 0;
Instead of doing
i %= TWO_PI:
But thanks for telling me what you did. That way I can move on to other things. I'd do : if ( i > TWO_PI ) i = i - TWO_PI;
You'll get smoother movement. - Ace
_____________________
"Free your mind, and your ass will follow" - George Clinton
|
Hiro Turnbull
Freelance Scripter
Join date: 20 Apr 2005
Posts: 24
|
05-01-2005 14:49
From: Danny DeGroot Hi Hiro,
I don't know if you've thought of this approach and discarded it, but here's something else that might work:
- rez a very small prim (say, a sphere or a cylinder flattened to a disk).
- set your orbiting object in the same plane as the new prim, and at a distance from it equal to your desired orbital radius. Then, link it to the new prim, selecting the new prim last of all. Since the new prim is now the root prim of the linkset, its coordinates will become the coordinates for the entire set.
- center the tiny prim inside your base object, and then apply llTargetOmega() to a script in the root prim. The root prim will act as the center of rotation.
== danny d. That is an awesome idea Danny. I did not think of that. Thanks for the tip it is perfect for what I want to do.
|
Francis Chung
This sentence no verb.
Join date: 22 Sep 2003
Posts: 918
|
05-01-2005 15:26
For what it's worth, fmod() (modulus for floating point numbers) is part of xycalc /15/03/9686/1.html
_____________________
-- ~If you lived here, you would be home by now~
|