hey guys, im trying to create a small game in which the player can drag back the mouse and release it to fire, so far so good and i have what i want. For the visual side of things im trying to get an arrow mesh to appear as i drag back, which shows the direction the ball will be fired. I want the arrow to stretch out on its local axis the further i drag back.
an example can be seen here http://www.youtube.com/watch?v=W3Ft4CnHRak&list=HL1380889751
any ideas how i can create this?
im really stuck =S
You will need a) point where your arrow starts and b) point where your arrow ends. Between these two points, you get a distance. You can use this varying distance to adjust the size of your arrow.
←
<----------
Yes?
i already have a script which calculates teh distance, however i cant seem to make the object change scale in real time
I’m guessing there’s 3 parts to that arrow. The head, the tail, and the part that stretches. You’ll need a script that places the head and tail appropriately, and adjust the scale along 1 axis for the center.
Alternatively, you could write a script that adjusts the vertices on the fly, but that doesn’t seem like it’ll work as well.
Have you got the art already?
Start with a cube and get it to change scale in real time. Then worry about the rotation angle and the length. Vector2d has a distance and angle function which might work, or you could use a ray into the 3d world, but that might cause problems.
yeah what i have so far is a 3d world and the camera is in orphographic view.
can you look at my code and see where im going wrong?
here is the small bit of code (lines 194 to 203) which is my update section
void Update()
{
Debug.Log (dragDistance);
Vector3 temp = ArrowPrefab.transform.localScale;
temp.z = dragDistance;
ArrowPrefab.transform.localScale = temp;
}
full code can be seen here>>> codeviewer.org
So basically, you found someone else’s script and can’t get it to work. My guess is that it works fine and you are using it wrong. Does it give any errors, warnings?
On another note, you are only cheating yourself doing this. Chances are your game won’t be a huge hit or anything, so most of what you get out of it is the learning experience. You may have to start with a simpler game, but it will be more rewarding because you did it yourself.
not at all, the script worked fine at 1st, however im adding in new features to it to get the game i desire, im getting no warnings or log errors at all.
I have just made a simple mini golf game with some features that make it stand out, most of what i have learnt has been through forum posts like this. The community is helpfull and i dont just copy and paste the answers. i take the time to understand what the mean.
You’ll have to be a little more specific of the problem then. The scaling part of the update works. Part of the learning process is learning to debug your own code. Isolate the problem and get feedback from the program itself, either by print statement or debug. We can help you a little with a specific problem, but we can’t really debug that much code for you. Make a model of what you want to do in a separate project and build the code all by itself so there aren’t any other problems added.
thankyou, ive tried what you said and it appears it was something to do with the prefab of the arrow, i tried using an arrow mesh which is in the scene already and indeed it scales up and down how i want. now i just need to find a way to make this invisible until the mouse is clicked and held down, thats easy but making the arrow face the right direction could be tricky