Jump to content

Make turret Point() to direction on y axis


Slastraf
 Share

Recommended Posts

post-12189-0-73954100-1448131515_thumb.jpg

post-12189-0-61518200-1448131545_thumb.jpg

post-12189-0-30284500-1448131625_thumb.png

 

Above some screenshots that are important to understand the problem.

 

function Script:UpdatePhysics()

self.entity:Point(self.target, 1, Time:GetSpeed() * self.rotSpeed)

 

end

 

This is a part of my code.

 

The first screenshot is what happens when i run the game.

The crawler runs around a path, the turret points at him but is rotated in negative y.

What can I do to prevent this ?

Link to comment
Share on other sites

Try something like this after calling Point:

 

Vec3 newRot = self.entity:GetRotation(true)
self.enitity:SetRotation( Vec3( newRot.x, -newRot.y, newRot.z ), true)

 

This will negate the Y rotation for you. If this rotates the turret on the wrong axis then you can try adding a - before newRot.x or newRot.z.

Using Leadwerks Professional Edition (Beta), mainly using C++.

Windows 10 / Linux Mint, Visual Studio 2017. GPU: NVidia GeForce GTX970, CPU: Intel i7 7700K @ 4.20 GHz

Previously known as Evayr.

Link to comment
Share on other sites

 self.vector = self.target:GetPosition(true)-self.entity:GetPosition(true)

self.entity:AlignToVector(self.vector:Normalize(),2)

local newRot = self.entity:GetRotation(true)

self.entity:SetRotation( Vec3( 90, -180+newRot.y, newRot.z ), true)

Try something like this after calling Point:

 

Vec3 newRot = self.entity:GetRotation(true)
self.enitity:SetRotation( Vec3( newRot.x, -newRot.y, newRot.z ), true)

 

This will negate the Y rotation for you. If this rotates the turret on the wrong axis then you can try adding a - before newRot.x or newRot.z.

That helped in parts, at the top my new script.

Link to comment
Share on other sites

Hi,

 

make an hidden helper sphere at cannon pos and point it to the target then get y-rotation from this helper sphere and put it to the cannon (maybe add 180 to flip)

tryed quick code down there but not tested carefull to free the helper...

 

helper = Model:Sphere()

helper:Hide()

helper:SetColor(0.0,1.0,1.0)

helper:SetPosition(self.entity:GetPosition(true),true)

helper:Point(self.target, 1, Time:GetSpeed() * self.rotSpeed)

self.entity:SetRotation(self.entity:GetRotation(true).x,self.helper:GetRotation(true).y+180 ,entity:GetRotation(true).z,true)

 

 

cu

Volker

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...