Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Obsurveyor
Jan 10, 2003

Kire posted:

I'm trying to figure out the mouse support in python. I want to print the coordinates where a user has clicked inside the terminal window.
I have been working on a wrapper for libtcod in Ruby and mouse clicks are the one thing, so far, that simply refuse to work. I can get the coordinates just fine but not whether a mouse button is pressed. I will be continuing work on it this weekend and will let you know if I figure it out.

Adbot
ADBOT LOVES YOU

speng31b
May 8, 2010

Hanpan posted:

In case anyone cares, the guys at Unity have published a new tutorial which is actually really decent:

http://unity3d.com/support/resources/tutorials/car-tutorial

Anyone working on a Unity megathread? I'd love to get one going.

I wholeheartedly support the creation of a Unity megathread. I've only gotten into it recently, since I've been stubbornly creating a rendering engine in OpenGL for awhile now (there is a SERIOUS lack of good OpenGL-learning resources updated for non-immediate rendering and modern extension usage -- all the most-recommended tutorials are lamentably outdated).

But yes, if you're a decent enough programmer to learn an easy high-level (scripting) language (C#, Javascript, Boo Python), you have at your fingertips basically everything you'd want for a nice-looking game with the Unity free version other than dynamic shadows, AND you're licensed to sell it commercially.

I've poked around just about every corner of the internet having to do with do-it-yourself game creation, from the hard way (OpenGL/Direct3D/some eclectic mixture of open-source libraries) to the medium-hard way (Ogre3D). I must say, Unity3D is the definitive easy way. If you're not so much interested in learning the fundamentals of game physics/AI/rendering/networking and want to get a functional prototype up and running in a matter of hours, maybe even minutes, then Unity3D is simply the best choice there is.

I'm surprised it hasn't been mentioned more, to be honest. It's an incredibly mature engine with an active team and very modern technology -- oh, and it's compatible with basically every platform there is.

OneEightHundred
Feb 28, 2008

Soon, we will be unstoppable!
Could just discuss Unity here?

Corrupted Cable
Feb 6, 2010
Lately I've been wondering how character creation sliders ( like those in oblivion and most of todays new games ) are coded/done. I searched around and found very few articles on the subject.

If anyone got articles, examples of code or some hints ( whatever that is of help ), please reply.

Note: I'm refering to those sliders for thin/fat, long/short etc etc...

Obsurveyor
Jan 10, 2003

Obsurveyor posted:

I have been working on a wrapper for libtcod in Ruby and mouse clicks are the one thing, so far, that simply refuse to work. I can get the coordinates just fine but not whether a mouse button is pressed. I will be continuing work on it this weekend and will let you know if I figure it out.

Kire, I imagine you figured this out but in python, it should be as easy as:

code:
mouse = libtcod.mouse_get_status()
and
code:
mouse.lbutton
mouse.rbutton
mouse.mbutton
should give you the a 1 if the mouse is currently pressed or 0 if not.

My issue with Ruby, if anyone cares, was that I had to use :uint8 to read the correct value for the bool in the TCOD_mouse_t struct, not :bool, which probably means I need to do more testing with other bool function arguments and return values.

Hughlander
May 11, 2005

Corrupted Cable posted:

Lately I've been wondering how character creation sliders ( like those in oblivion and most of todays new games ) are coded/done. I searched around and found very few articles on the subject.

If anyone got articles, examples of code or some hints ( whatever that is of help ), please reply.

Note: I'm refering to those sliders for thin/fat, long/short etc etc...

Pretty sure they just adjust the length / distance between two bones... Try: http://www.peachpit.com/articles/article.aspx?p=483773&seqNum=3

Vinterstum
Jul 30, 2003

Corrupted Cable posted:

Lately I've been wondering how character creation sliders ( like those in oblivion and most of todays new games ) are coded/done. I searched around and found very few articles on the subject.

If anyone got articles, examples of code or some hints ( whatever that is of help ), please reply.

Note: I'm refering to those sliders for thin/fat, long/short etc etc...

* Bone push modifiers (making all vertices skinned to a specific bone move closer/further away from the bone, i.e. for making stuff bigger or smaller).
* Additive animations (moving bones around).

Probably more and different ways of doing this, but the above is what I've seen done.

Vinterstum fucked around with this message at 03:58 on Jun 6, 2010

The Oid
Jul 15, 2004

Chibber of worlds

Corrupted Cable posted:

Lately I've been wondering how character creation sliders ( like those in oblivion and most of todays new games ) are coded/done. I searched around and found very few articles on the subject.

If anyone got articles, examples of code or some hints ( whatever that is of help ), please reply.

Note: I'm refering to those sliders for thin/fat, long/short etc etc...

Generally this is done by blending between different skeleton configurations, and vertex morphs, based on the slider values.
So you'd have a variant of the player mesh, for each extreme of the slider, and just blend between the different variants, based on the relevant slider values. Similarly for the skeleton, you'd have a variant for a very tall character, a variant for a very fat character, etc, and blend between them appropriately.

The Oid fucked around with this message at 23:59 on Jun 6, 2010

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
Hello Gentlemen. I come to you with a very broad question in hopes that I can find a decent tutorial/example/resource on the issue.

I'm interested in building a roguelike engine in Java (No, I don't want to use some one else's mostly as I think I would learn a lot more if I attempted to build my own, and if I would finish it, I could do a lot more with it), but I don't know even where to start with the UI. I have a pretty good grasp on how to build the back end of the system, but I have no idea how to even build a simple window, set the font to something monospace and track (X,Y). I've googled a fair bit for a decent tutorial, but have found very little that could be construed as helpful. I'm hoping one of you fine folk could direct me to a resource that could start me up on this project.

iopred
Aug 14, 2005

Heli Attack!

Canine Blues Arooo posted:

Hello Gentlemen. I come to you with a very broad question in hopes that I can find a decent tutorial/example/resource on the issue.

I'm interested in building a roguelike engine in Java (No, I don't want to use some one else's mostly as I think I would learn a lot more if I attempted to build my own, and if I would finish it, I could do a lot more with it), but I don't know even where to start with the UI. I have a pretty good grasp on how to build the back end of the system, but I have no idea how to even build a simple window, set the font to something monospace and track (X,Y). I've googled a fair bit for a decent tutorial, but have found very little that could be construed as helpful. I'm hoping one of you fine folk could direct me to a resource that could start me up on this project.

You could start by doing it in console, no need to go GUI for it.

If you want full curses support:
http://roguebasin.roguelikedevelopment.org/index.php?title=Java_Curses_Implementation

Chris Awful
Oct 2, 2005

Tell your friends they don't have to be scared or hungry anymore comrades.
Is it possible to set the origin in opengl to the topleft part of the screen, and keep it there when resizing the window?

haveblue
Aug 15, 2005



Toilet Rascal

Chris Awful posted:

Is it possible to set the origin in opengl to the topleft part of the screen, and keep it there when resizing the window?

You can't make it happen magically for free within GL itself, but it's pretty easy to put something that restores that setup in the reshape handler or whatever your windowing system uses.

heeen
May 14, 2005

CAT NEVER STOPS

Chris Awful posted:

Is it possible to set the origin in opengl to the topleft part of the screen, and keep it there when resizing the window?

You can use gluOrtho2D with the values for top end bottom swapped and you'll have the y-axis flipped.

chemosh6969
Jul 3, 2004

code:
cat /dev/null > /etc/professionalism

I am in fact a massive asswagon.
Do not let me touch computer.

Kire posted:

Does anybody have any experience with the libtcod library for making roguelikes?
http://doryen.eptalys.net/libtcod/

I'm trying to figure out the mouse support in python. I want to print the coordinates where a user has clicked inside the terminal window.

I started with this

http://roguebasin.roguelikedevelopment.org/index.php?title=Complete_Roguelike_Tutorial,_using_python%2Blibtcod

The tutorial isn't complete and about halfway through, the "Here's the code so far" is bad as it stops being incremental. You'll see stuff that you would have removed by that point and it begins to look like a big copy/paste thing that was meant to be cleaned up later. I got to the dungeon generation and lost motivation since it doesn't go much further than that.

Right now I'm working on doing characters and the combat system based off of http://en.wikipedia.org/wiki/Middle-earth_Role_Playing which is brutal as hell. You have eyes being hit with arrows, limbs being hacked off, disemboweling characters and possibly getting your weapon stuck, among other things. The big thing now is an rear end load of typing all the critical hits and fumbles and then that part will mostly be finished.

I'm not even thinking about adding in magic at this point.

HolaMundo
Apr 22, 2004
uragay

sponge would own me in soccer :(
I've been trying to figure out how game worlds like the ones in Braid are achieved (you can see a bit here http://www.davidhellman.net/blog/the-art-of-braid-part-4/). Instead of using tiles (with a fixed size) they use "pieces" which can be resized and placed anywhere in the level.
I'm guessing it might not be so hard, but I googled to find articles about this or atleast what data structures can be used but had no luck.

Does anyone have any idea about this? Or if you know of any article explaining how it works, please post a link to it.

Obsurveyor
Jan 10, 2003

Well, it looks like there is no special data structure. He is just rendering sprites(the "pieces") and using invisible collision detection structures. Rendering a sprite with two triangles or one quad gives you the rotating, scaling, tinting and clipping practically for free. All you have to do is save where those are in placed in space for a level. Collision detection looks like it could be as simple as rectangles. I am not sure what the squares in the upper left corner of each one are, but they are probably the transformation point for the editor.

In summary, I think you are over analyzing what is going on here. Just go for it! :)

haveblue
Aug 15, 2005



Toilet Rascal

HolaMundo posted:

I've been trying to figure out how game worlds like the ones in Braid are achieved (you can see a bit here http://www.davidhellman.net/blog/the-art-of-braid-part-4/). Instead of using tiles (with a fixed size) they use "pieces" which can be resized and placed anywhere in the level.
I'm guessing it might not be so hard, but I googled to find articles about this or atleast what data structures can be used but had no luck.

Does anyone have any idea about this? Or if you know of any article explaining how it works, please post a link to it.

The most advanced data structure for a collection of 2D regions is probably the quadtree, but modern hardware is so far past the demands of Braid's scenes that he may as well just do a simple bounds check on everything in the world or throw it at DX/GL and let the clip stage deal with it.

Imazul
Sep 3, 2006

This was actually a lot more bearable than most of you made it out to be.

HolaMundo posted:

I've been trying to figure out how game worlds like the ones in Braid are achieved (you can see a bit here http://www.davidhellman.net/blog/the-art-of-braid-part-4/). Instead of using tiles (with a fixed size) they use "pieces" which can be resized and placed anywhere in the level.
I'm guessing it might not be so hard, but I googled to find articles about this or atleast what data structures can be used but had no luck.

Does anyone have any idea about this? Or if you know of any article explaining how it works, please post a link to it.

You are in luck, I had been looking into that and I found a working editor/tutorial to see how it works.

http://gametuto.com/in-game-c-map-e...-aquaria-games/

HolaMundo
Apr 22, 2004
uragay

sponge would own me in soccer :(

Obsurveyor posted:

In summary, I think you are over analyzing what is going on here. Just go for it! :)

I think you are right. I thought about using quadtrees but just kept thinking over and over how to do pretty much everything instead of just sitting down and get coding and handle problems as they pop up.

Imazul posted:

You are in luck, I had been looking into that and I found a working editor/tutorial to see how it works.

http://gametuto.com/in-game-c-map-e...-aquaria-games/

Cool, gonna download and check it out.

Thanks for all the replies :)

scjohnno
Apr 1, 2010
You can also activate Braid's editor by passing the '-editor' flag to the exe, and then pressing F11 in-game. I wasn't sure if you already knew that.

I wrote a level editor as part of a game for a University project. I didn't use quad-trees or anything fancy; I just stored each object's position. The editor wasn't particularly difficult to create, but I also didn't put a lot of effort into making it usable. You'd probably spend more time on UI improvements than you would on the nuts-and-bolts of it.

seregrail7
Nov 3, 2006

HolaMundo posted:

I've been trying to figure out how game worlds like the ones in Braid are achieved (you can see a bit here http://www.davidhellman.net/blog/the-art-of-braid-part-4/). Instead of using tiles (with a fixed size) they use "pieces" which can be resized and placed anywhere in the level.
I'm guessing it might not be so hard, but I googled to find articles about this or atleast what data structures can be used but had no luck.

Does anyone have any idea about this? Or if you know of any article explaining how it works, please post a link to it.

This is the method I use for the game I'm working on. I'm not sure what area you want to be explained? Here's the basics of how it works for me, using XNA.

Sprites are made of a Texture, Rectangle(the bit to draw) then rotation, tint, scale etc. When I load a level, the sprites are all thrown into a Camera class that stores them in layers(basically a list along with some other things), which have movement speed for doing parallax scrolling. Layers can be sorted every frame or not(only the one with characters on it is sorted every frame), these layers are then rendered in order with a matrix applied to them for scale/rotation of the actual camera itself(for zooming in and out, doing camera shakes or whatever).

For saving them, I keep an 'original' copy of the sprite, then just save the reference of that in the level data. So let's say I have a sprite called rock, the source file will contain what texture it uses and the source. Then in the level data it saves the sprite with the source as rock, then all the other details unique to that one sprite like rotation and tint. This is simply because if I need to rearrange a sprite sheet at some point I can change the source sprite and it will be applied to everything in the level, which is very handy.

Collision is totally seperate, I just use boxes but depending on how the terrain works you might need to use polygons.

Like others said, hardware is so powerful now that it's not difficult at all to do.

HolaMundo
Apr 22, 2004
uragay

sponge would own me in soccer :(
Do you go through all the lists checking one by one which sprites should be drawn or is there a more effective way to do this?

seregrail7
Nov 3, 2006
I do it when I'm drawing the sprite, a simple bounds check doesn't take much time to do.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

In Unity, how do you make a Gameobject (with Rigidbody and Collider) ignore collisions with clones of itself? I know how to stop them from interacting with the objects that fire them, but I want the cloned bullets to pass through each other instead of knocking each other away.

brian
Sep 11, 2001
I obtained this title through beard tax.

You either have to make the bullet use a trigger collider (with the rigidbody) and rely on OnTrigger messages, or, use Physics.IgnoreCollision() between each object you don't want to collide with manually. The latter is more what you described but is one of the most annoying issues with Unity (lack of collision groups) and usually using trigger colliders is going to be better unless you really really need collision data (intersection/normal).

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
Bouncing off the idea of just using a console, I found JCurses, which seems to do what I want and giving me the flexibility I need. The problem is that there seems to be very little external documentation/tutorials/whatnot available and while the Java Docs are incredibly useful once I have the basic functionality of the library down, How to generate something as simple as a window with a line of text evades me. I've found one snippit of example code online that looks like so:

code:
import jcurses.system.CharColor;
import jcurses.widgets.*;

public class Main
{
    public static void main(String[] args) throws Exception
    {    
        Window w = new Window(40, 20, true, "Hello World Window");

        DefaultLayoutManager mgr = new DefaultLayoutManager();
        mgr.bindToContainer(w.getRootPanel());
        mgr.addWidget(
            new Label("Hello World!", new CharColor(CharColor.WHITE, CharColor.GREEN)),
            0, 0, 40, 20,
            WidgetsConstants.ALIGNMENT_CENTER,
            WidgetsConstants.ALIGNMENT_CENTER);

        w.show();
        Thread.currentThread().sleep(5000);
        w.close(); // reset the native console
    }
}

While the code does compile, it fails at runtime, throwing a Null Pointer Exception on the line where you create the Window object. Is there a better set of examples available as I'm simply not familiar enough with this type of stuff to figure it out without tons of trial and error.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

I haven't done any geometry since high school and forgot it all a long time ago. I have a cannon and a rotating turret. The cannonballs are created at the end of the turret and fly off. I have the "fly off" part working.

I wrote a big long explanation of my problem but I couldn't make any sense of it after I wrote it so here's an illustration instead.



If the cannon is pointing at (x,y), how do I get X and Y so my cannonballs come out of the right place? I'm still using Unity.

Mata
Dec 23, 2003

Luigi Thirty posted:

I haven't done any geometry since high school and forgot it all a long time ago. I have a cannon and a rotating turret. The cannonballs are created at the end of the turret and fly off. I have the "fly off" part working.

I wrote a big long explanation of my problem but I couldn't make any sense of it after I wrote it so here's an illustration instead.



If the cannon is pointing at (x,y), how do I get X and Y so my cannonballs come out of the right place? I'm still using Unity.

cos(Angle of turret) * Length of turret = X
sin(Angle of turret) * Length of turret = Y

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Mata posted:

cos(Angle of turret) * Length of turret = X
sin(Angle of turret) * Length of turret = Y

I am hopelessly confused and can't get it to work. The cannon is pointing down the Z axis (making it the X axis) or something. And even when I do correct for that, I still get really weird results that make no sense if I'm rotating anywhere other than 0 degrees. I have never felt more retarded :saddowns:

Can someone figure out what I'm supposed to be doing?

e: New code below

Luigi Thirty fucked around with this message at 23:31 on Jun 15, 2010

Spite
Jul 27, 2001

Small chance of that...

Mata posted:

cos(Angle of turret) * Length of turret = X
sin(Angle of turret) * Length of turret = Y

It depends on where the angle starts at. If 0 deg points up, then the sin/cos need to be reversed.
R * cos(0) = R
R * sin(0) = 0
which would put straight up as (L, 0)

EDIT
Basically, consider that a circle contains the angles from 0 - 2PI.
cos(0) == 1
sin(0) == 0
Depending on where you want your 0 angle to be, you can define any point on the circle by:
r*cos(theta) and r*sin(theta)
You can extrapolate this to points on a sphere as well, look up Spherical Coordinates.

Also, the vector your cannonball comes out at needs to have y = 0 or you'll be firing off at an angle instead of straight.
The vector needs to be x, 0, z - (center of tank).

Spite fucked around with this message at 23:19 on Jun 15, 2010

Bakkon
Jun 7, 2006

SQUIRTLE SQUAD

Luigi Thirty posted:

I am hopelessly confused and can't get it to work. The cannon is pointing down the Z axis (making it the X axis) or something. And even when I do correct for that, I still get really weird results that make no sense if I'm rotating anywhere other than 0 degrees. I have never felt more retarded :saddowns:

If it's only correct at 0 degrees, it sounds like you should be converting to radians before the cos/sin functions.

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Bakkon posted:

If it's only correct at 0 degrees, it sounds like you should be converting to radians before the cos/sin functions.

Helpfully, the cos/sin functions say they return radians but don't say whether they take radians or degrees. :mad:

I adjusted the code around. At 0 degrees, this gives me (0, 2) which is correct. At 180 degrees, I get (1.68, 1.08) which is obviously not correct.

Spite posted:

Also, the vector your cannonball comes out at needs to have y = 0 or you'll be firing off at an angle instead of straight.
The vector needs to be x, 0, z - (center of tank).

With the Vector3.forward always shoots in the direction the tank is pointing.

code:
var cannonPower = 20.0;

function Update () {

	//gently caress THIS loving THING gently caress

	var cannonPositionY = 2 * (Mathf.Cos(transform.rotation.y)); //Y
	var cannonPositionX = 2 * (Mathf.Sin(transform.rotation.y)); //X
	
	//var cannonPositionX = (Mathf.Cos(rotAlignToCannon) * 2); //X
	//var cannonPositionY = (Mathf.Sin(rotAlignToCannon) * 2); //Y
		
	print(cannonPositionX + "," + cannonPositionY);

	//print(cannonPower);

	if (Input.GetKeyDown("r")){
		cannonPower += 1;
	}
	
	if (Input.GetKeyDown("e")){
		cannonPower -= 1;
	}

	if (Input.GetButtonDown("Fire2")) {
		var clone : Rigidbody;
		var cannonFirePosition = transform.position; //Cannonball from cannon
		
		cannonFirePosition.x += cannonPositionX; //X
		cannonFirePosition.y += 1.5;
		cannonFirePosition.z += cannonPositionY; //Y
				
		clone = Instantiate(cannonball, cannonFirePosition, transform.rotation);
		
		clone.velocity = transform.TransformDirection(Vector3.forward * cannonPower);
	}
}

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Luigi Thirty posted:

Helpfully, the cos/sin functions say they return radians but don't say whether they take radians or degrees. :mad:

No cos or sin function in the world returns radians. They return unitless numbers which are projections of a unit vector on to either the X or Y axis, respectively.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!


var cannonPositionY = 2 * (Mathf.Cos(transform.rotation.y)); //Y
var cannonPositionX = 2 * (Mathf.Sin(transform.rotation.y)); //X


Well, for one thing, this is likely not right :)

Luigi Thirty
Apr 30, 2006

Emergency confection port.

ShoulderDaemon posted:

No cos or sin function in the world returns radians. They return unitless numbers which are projections of a unit vector on to either the X or Y axis, respectively.

Er, right. I told you I don't remember any of this.

cos() and sin() seem to want radians, but multiplying transform.rotation.y by Deg2Rad doesn't seem to be helping anything (now it always stays within a few hundredths of (0,2)). I'll keep hammering at it.

Dijkstracula posted:


var cannonPositionY = 2 * (Mathf.Cos(transform.rotation.y)); //Y
var cannonPositionX = 2 * (Mathf.Sin(transform.rotation.y)); //X


Well, for one thing, this is likely not right :)

The cannon's only rotating in the Y axis. I'm trying to get the (x,y) offset I need to put the cannonball in the right place.

Pfhreak
Jan 30, 2004

Frog Blast The Vent Core!
Mathf.Sin takes a float in radians, and returns the sin. You know that transform.rotation returns a quaternion, right? You probably want transform.rotation.eulerangles.y

Edit: I'm assuming this is Unity, I've been reading their documentation here: http://unity3d.com/support/documentation/ScriptReference/Quaternion.html and assuming I'm looking at the same thing you are.

Null Pointer
May 20, 2004

Oh no!

Dijkstracula posted:


var cannonPositionY = 2 * (Mathf.Cos(transform.rotation.y)); //Y
var cannonPositionX = 2 * (Mathf.Sin(transform.rotation.y)); //X


Well, for one thing, this is likely not right :)

Right line, wrong problem.

What you want is to rotate the vector (0,2) around the point (0,0) by an angle 't'. What you also want to do is memorize this matrix:

|cos(t) -sin(t)|
|sin(t) cos(t) |

Which is the form of all rotations in any plane with respect to a certain basis.

|cos(t) -sin(t)| |0|
|sin(t) cos(t) |*|2|=(0*cos(t) - 2*sin(t), 0*sin(t) + 2 * cos(t))

So your X coordinate should be -2*sin(t) and your Y coordinate should be 2*cos(t).

You also need to convert your angle into radians before calling sine or cosine. pi * sin(t))/180 != sin(pi*t/180)

Luigi Thirty
Apr 30, 2006

Emergency confection port.

The winner is:

pre:
var cannonPositionX = 2 * (Mathf.Sin(Mathf.Deg2Rad * transform.rotation.eulerAngles.y)); //X
var cannonPositionY = 2 * (Mathf.Cos(Mathf.Deg2Rad * transform.rotation.eulerAngles.y)); //Y
Which fires a ball out of the cannon from any Y-axis rotation. Thanks for clearing it up for me. Now I can drive my tank around and knock over stacks of physics objects. :c00l:



I think I'm going to work on my 3D modeling skills.

edit: The Lightwave FBX exporter plugin is a piece of poo poo, by the way. It will produce an FBX file which contains one layer of my model (yes, both are selected in Modeler). If you try to use it to export more than one model without closing and re-opening Lightwave, it'll create a blank FBX file. :mad:

Luigi Thirty fucked around with this message at 05:55 on Jun 16, 2010

Torch Dexter
Dec 3, 2006

I'm glad to see you've sorted this out on your own, but I think you may be needlessly complicating things here. If I understand what you were trying to achieve here, you have a turret that you rotate can rotate left and right and wanted to work out the position of the end of the barrel from its rotation around the y axis.

You already know how to find the forward vector of the turret's transform as you are using it to launch the projectiles in the right direction. So all you need to do is add that vector (multiplied by the length of the barrel in m) to your transform.position.

(Also to find the forward vector you can just use transform.forward instead of transform.TransformDirection(Vector3.forward))

So messing around with your previous posted example you would end up with something like:
code:
var cannonPower = 20.0;

function Update () {

	if (Input.GetKeyDown("r")){
		cannonPower += 1;
	}
	
	if (Input.GetKeyDown("e")){
		cannonPower -= 1;
	}

	if (Input.GetButtonDown("Fire2")) {
		var clone : Rigidbody;
		var cannonFirePosition = transform.position; //Cannonball from cannon
		
		cannonFirePosition.y += 1.5;
		cannonFirePosition += transform.forward*2;
				
		clone = Instantiate(cannonball, cannonFirePosition, transform.rotation);
		
		clone.velocity = transform.forward * cannonPower;
	}
}
And of course there's also the non-coding solution of sticking an empty GameObject as a child of the turret where the end of the cannon should be, and using that object's transform position as the origin point for the cannonballs.

If I haven't misunderstood what you were trying to achieve here, I hope this is of some help.

Torch Dexter fucked around with this message at 17:13 on Jun 16, 2010

Adbot
ADBOT LOVES YOU

Luigi Thirty
Apr 30, 2006

Emergency confection port.

Torch Dexter posted:

And of course there's also the non-coding solution of sticking an empty GameObject as a child of the turret where the end of the cannon should be, and using that object's transform position as the origin point for the cannonballs.

If I haven't misunderstood what you were trying to achieve here, I hope this is of some help.

I thought of this but dismissed it as the cheap way out.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply