help: forward, behind despite car's angles?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

help: forward, behind despite car's angles?

Post by Elgan »

Im tryign to get the angles forward of my car thing. But When i go up a hill it's angles are forward up cos the car is pointing up. How can i get the forward angles of the car as if it was pointing forward still?

Image

Code: Select all

	local.fwd  = local.ship.forwardvector - local.ship.upvector 
	self.origin = local.ship.origin - ( 0 0 0 ) - local.fwd * 250 + 0.05 * local.fwd * local.ship.speed

end
Image

Sorry i made a mistake i dont think angles is the word i wanted to use. I want to get the place forward on forward angles despite the angles of the car changing.

Also i realised when the car's angles[1] are normal it wud cause the cam to point down.

S i need to to be changing when going up and down hills. - Ill do this later but for now i still working on the forward behind position.
Last edited by Elgan on Tue Feb 08, 2005 1:54 pm, edited 3 times in total.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

Angles

Post by tltrude »

"Angles" is a three part number for X, Y, and Z. They can be used by asking for them by numbers 0, 1, and 2. But the numbers have to be in brackets.

[0] [1] [2]

Here is an example from a global script called "wombat_moveit"--may be easier to read if you copy it to Notepad.

Code: Select all

//  Script by Wombat   dpwyatt@iprimus.com.au

//	A small request. If you use this script, and you like it, email me, with your gratitude ? I would love to read where my
// 	script is being used . Thanks. Enjoy

//  Move it script, similar to a projectile, from an exploder, but allows you to set things like
//  the number of frames, to animate too, the angle and position of the end result of an explosion.

//  Usage:

//  (Original.object) thread global/wombat_moveit.scr::moveit (script_origin) (path of destroyed model) (number of frames)(bomb emitter)(effect)

//  for example:

//  1.  Set up a script_model of your truck/tank etc
//		Set angles [key] and  X Y Z [value] to the starting position.
//		Set a targetname  (garage_truck)
//  2.  Set up a script_origin
//		Set a targetname  (garage_truck_moveto)
//		Set the angles to the position you want the model to be in finished position
//
// This is best done by another script_model set to the destroyed position, and model. Make note of the origin value,
// This model has served its purpose, so delete it
// Position the script_origin at the recorded origin coords. ( I found I had to move it there physically, so to speak
// as setting it in the origin [key] of the script_origin didn't work). 

// From the thread that is called to trigger the event, whether that be a damage trigger, or bomb etc.
// call the global/wombat_moveit.scr::moveit script

//   eg:   $garage_truck thread global/wombat_moveit.scr::moveit $garage_truck_moveto vehicles/opeltruck_d.tik 25

//  This will give the script the start position, and angles, the end position, and angles. The destroyed model to display, 
//  and the number of frames to animate to ( each frame 0.02 sec). Animation takes three seconds, so the number of frames is (3/0.02) or
//  150 frames..  The change in angle, and change in position, is divide by the number of frames for a smooth animation..... 

//  If this is a multi part move then use a thread to run the wombat_moveit script and use waitthread instead of thread, using
//  script_origins, strung together, to form a path. 

//  ie :
//	thread garage_truckmove		// call this thread to allow the called thread to continue running
//					// use for more than one path objected truck ( a convoy ?? ) 
//     ........
//	garage_truckmove:
//		$garage_truck waitthread global/wombat_moveit.scr::moveit $garage_truck_moveto vehicles/opeltruck_d.tik 25
//		// wait until first move finished , then set to next target
//		$garage_truck waitthread global/wombat_moveit.scr::moveit $garage_truck_moveto2 vehicles/opeltruck_d.tik 40
//		// still waiting, truck moving slower though  [( more frames = slower ) over the same distance]
//		$garage_truck thread global/wombat_moveit.scr::moveit $garage_truck_movetoEND vehicles/opeltruck_d.tik 25
//		// just go and end the thread
//	end



//       My script follows


moveit local.moveto local.endmodel local.framenumber:	// local variables
									// means you can call the script more than once ( 2 or 3 trucks at once )
	local.start1x = self.angles[0]					// the x part of the angles array
	local.start1y = self.angles[1]					// y etc
	local.start1z = self.angles[2]
	local.movex = local.moveto.angles[0] - local.start1x		// change this much per frame ( x )
	local.movey = local.moveto.angles[1] - local.start1y		// y etc
	local.movez = local.moveto.angles[2] - local.start1z
	if ( local.movex >180 ) {local.movex -= 360 }			// go the short way
	if ( local.movey >180 ) {local.movey -= 360 }
	if ( local.movez >180 ) {local.movez -= 360 }
	//println local.movex " , " local.movey " , " local.movez	//debugging
	local.movex = local.movex / local.framenumber
	local.movey = local.movey / local.framenumber
	local.movez = local.movez / local.framenumber
	//println local.movex " , " local.movey " , " local.movez	//debugging
	
	self model local.endmodel						// change the model

	local.vec = local.moveto.origin - self.origin 				// create a vector for the origin manipulations

	
	local.vec[0] = local.vec[0] / local.framenumber				// divide the vector by #frames (x)
	local.vec[1] = local.vec[1] / local.framenumber				// y etc
	local.vec[2] = local.vec[2] / local.framenumber
		
	
	for (local.i=1;local.i<=local.framenumber;local.i++){			// loop for this number of frames

		
		local.start1x += local.movex					// reads  start1x = start1x + movex
		local.start1y += local.movey
		
		local.start1z += local.movez
		

		if (local.start1z <0 ){local.start1z += 360}			// if angle goes negative then make it positive again

		self.angles = (local.start1x local.start1y local.start1z)	// set the new angles of the script_model
		//println self.origin 						// debugging
		//println local.vec
		self.origin += local.vec					// add the vector to the origin
		
		//println local.start1x "," local.start1y "," local.start1z
		wait .02
		}
		
end
Hope that helps--don't ask me how it works, ha ha.

Your images are probably not working in the forum because they are bmp format.
Tom Trude,

Image
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

I didnt look at the script yet the light is on the screen and i cant see a damn thing but it sounds gd from what i cna make out. but i think it might not help , i realised i errord.

Sorry i made a mistake i dont think angles is the word i wanted to use. I want to get the place forward on forward angles despite the angles of the car changing.

Also i realised when the car's angles[1] are normal it wud cause the cam to point down.

S i need to to be changing when going up and down hills. - Ill do this later but for now i still working on the forward behind position.
User avatar
tltrude
Chuck Norris
Posts: 4774
Joined: Sun Jul 07, 2002 4:03 am
Location: Oklahoma, USA
Contact:

-

Post by tltrude »

local.fwd = local.ship.angle
Tom Trude,

Image
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Re: -

Post by Elgan »

tltrude wrote:local.fwd = local.ship.angle
thats an angle. I need the vector forward of the ships angles. But i need to get this forward vector despite the angles.

Its hard to explain:(. Wish them dman pics would work!

so ur behind the ship but when the ship changes angle ur still behind. but if it goes up a hill the ships angle changes so u wud be below. IDont want to be below.
jv_map
Site Admin
Posts: 6521
Joined: Tue Sep 03, 2002 2:53 pm
Location: The Netherlands
Contact:

Post by jv_map »

Ah it's rather simple actually, just take self.forwardvector and remove any component out of the XY plane.

3 ways:

(elegant: subtract projection on z-axis from fwd vector)

Code: Select all

local.fwdvec = self.forwardvector - self.forwardvector * $world.upvector * $world.upvector
local.fwdvec = vector_normalize local.fwdvec
(elegant: decompose fwd vector in X Y directions)

Code: Select all

local.fwdvec = self.forwardvector * $world.forwardvector * $world.forwardvector
local.fwdvec += self.forwardvector * $world.leftvector * $world.leftvector
local.fwdvec = vector_normalize local.fwdvec
(ugly but works)

Code: Select all

local.fwdvec = self.forwardvector
local.fwdvec[2] = 0.0
local.fwdvec = vector_normalize local.fwdvec
The vector_normalize requires local.fwdvec to be non-zero, i.e. the vehicle may not be pointing straight up.
Image
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

ah way cool ill try it tomorrow.

world has a upvector. w00t. why?:S.

ill mess tomoz. ty again:D
Elgan
Site Admin
Posts: 890
Joined: Tue Apr 13, 2004 10:43 pm
Location: uk
Contact:

Post by Elgan »

not tomorrow but hey works , not bad.hehe

i whent for local.fwd = self.forwardvector - self.forwardvector * $world.upvector * $world.upvector
local.fwd = vector_normalize local.fwd cos it loks cooler.


$world.upvector * $world.upvector:S..

ty



Can i add to a vector or wud i have to do something like above?

i mean something like.

local.ship.lastpos = local.ship.forwardvector + local.shipleftvector * local.ship.angle[2]

ive decided to try steering the ship by its lean instead of changing the errm z2 angle thing. if any1 understands that? So i can turn it and it will lean to turn then go back to normal angle and steering will be straight also. Thus when its at an angl the steering wont be straight. This could look bad when the suspension isnt there it would cause the car to turn in the direction it is angling. So i want that too:D


EDIT

ok talking to myself again.

local.ship.lastpos = local.ship.forwardvector + local.ship.leftvector * (int local.ship.angles[2] / 100)


tried that.

(int local.ship.angles[2] / 100) to lower it cos i was going wayy fast.

Think im wayy of track 2. I just go sideways!
Post Reply