Jump to content

Rotate Vehicle??


Yue
 Share

Recommended Posts

I have a vehicle that is made up of several joints, sliders and hinges. 

I don't know how to turn the vehicle, i.e. by script, change its angle on its Y-axis, or change its initial position.  If I try it like I really did with SetPosition, or SetRotation, I don't get the results I expected. 

That is, I can only mark its position and initial angle using the map editor, but I can't do it by script.  


Translated with www.DeepL.com/Translator (free version)

image.thumb.png.b7a213f1b62e2ac64937fb9c328bdf98.png

 

  • Like 1

 

 

Link to comment
Share on other sites

Here Script vehicle System.

 

-- **********************************************************
-- Fichero Script 	: 	CVehicle.lua
-- Notas			:	Fichero Clase para objeto / Vehiculo.
-- Scripter			: 	Yue Rexie.
-- **********************************************************
-- Sitio Web		: 	http://www.iris3dgames.ga
-- Fecha			:   Viernes 10 de Enero / 2020
-- **********************************************************

vehicle = {}

	function vehicle:New(chassis,wheels,springs,axis)

		
				
			local this = {}


			function this:Start()
				
				this.chassis 	= chassis
				this.wheels		= wheels
				this.springs 	= springs
				this.axis		= axis

			
				this.axisFL		= nil
				this.axisFR		= nil

				this.springFL	= nil
				this.springFR	= nil
				this.springBL 	= nil
				this.springBR 	= nil

				this.hingeWFL  	= nil
				this.hingeWFR	= nil
				this.hingeWBL	= nil
				this.hingeWBR	= nil

			end

			this:Start()

			function this:Init()

				self:InitSprings()
				self:InitMotorWheels()
				self:InitAxisW()

			end

			function this:InitAxisW()
			
				self.axisFL = self:CreateHinge(self.axis.FL, self.springs.FL,0,1,0)
				self.axisFR = self:CreateHinge(self.axis.FR, self.springs.FR,0,1,0)

				self.axisFL:EnableLimits()
				self.axisFR:EnableLimits()
				self.axisFL:SetLimits(0,0)
				self.axisFR:SetLimits(0,0)
			end

			function this:InitSprings()

				self.springFL = self:CreateSpring(self.springs.FL)
				self.springFR = self:CreateSpring(self.springs.FR)
				self.springBL = self:CreateSpring(self.springs.BL)
				self.springBR = self:CreateSpring(self.springs.BR)

			end 


			function this:InitMotorWheels()

				self.hingeWFL = self:CreateHinge(self.wheels.FL,self.axis.FL, 1,0,0)
				self.hingeWFR = self:CreateHinge(self.wheels.FR,self.axis.FR, 1,0,0)
				self.hingeWBL = self:CreateHinge(self.wheels.BL,self.springs.BL,1,0,0)
				self.hingeWBR = self:CreateHinge(self.wheels.BR,self.springs.BR,1,0,0)

			end

			function this:Update()

				if Window:GetCurrent():KeyDown(Key.F) then

					self.chassis:AddForce(0,5000,0)
				end
				
			end

			-- Joints.
			function this:CreateHinge(child,parent,pinX, pinY, pinZ)

				local posChild = child:GetPosition(false)
				
				local h = Joint:Hinge(posChild.x, posChild.y, posChild.z, pinX, pinY, pinZ, child, parent)
			
				return h

			end

			function this:CreateSpring(spring)

				local posSpring 	= spring:GetPosition(false)
				
				local s = Joint:Slider(posSpring.x,posSpring.y,posSpring.z, 0,1,0,spring, self.chassis )
				s:EnableLimits()
				s:SetLimits(-0.05,0.02)
				s:SetSpring(1,0.5,1)
				return s
			end


		
			return this

 

 

 

Link to comment
Share on other sites

6 hours ago, Josh said:

Maybe you need to move the vehicle and all tires?

I have tried to move the tires and the whole vehicle, but the tires for example rotate relative to their local coordinate and not relative to the vehicle.  
image.png.11dca2b468ba3817cfc6e880b682480c.png

 

6 hours ago, Josh said:

The new car looks a million times better, by the way.

You always get better at something, over and over again practicing you always see something more beautiful. 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...