AttackGorilla Posted August 25, 2020 Share Posted August 25, 2020 If I have a player moving through water I am using: "node.WorldPosition += node.GetWorldDirection(MathLib.AXIS.Y)*speed*Game.IFps;" with "private void Update()" and "Input.IsKeyPressed" While the moving player still causes ripples in the water (which is great), the player loses buoyancy and just floats and ignores water wave height interaction (which is no good). When the player is static (no key is pressed) the physics will resume correctly. Is there a way to move the player and still allow for water physics to impact the player movement, or a way to ensure player object physics update each frame? Link to comment
silent Posted August 25, 2020 Share Posted August 25, 2020 AttackGorilla Is it possible to check the whole code for player? If you can also provide a small test example - that would be really useful :) How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
AttackGorilla Posted August 25, 2020 Author Share Posted August 25, 2020 I have a water mesh and I am moving a simple rigid body primitive through the water. The primitive is moved by the water when no keys are pressed, but when I press a key to move the primitive the primitive will still impact the water but the water no longer impacts the primitive on any axis. (I am assuming there must be a better way to adjust the position when a key is pressed that will still allow for impact from the water.) THANK YOU using System; using System.Collections; using System.Collections.Generic; using Unigine; [Component(PropertyGuid = "465a782496696533c01668f62b6a4bdd33a3db98")] public class player_boat_01 : Component { public float move_speed = 10.0f; public float turn_speed = 90.0f; public int health = 50; [ParameterFile(Filter = ".node")] public string death_fx; private void Init() { // write here code to be called on component initialization } private void Update() { // write here code to be called before updating each render frame if(Input.IsKeyPressed(Input.KEY.W)) { move(move_speed); } if(Input.IsKeyPressed(Input.KEY.S)) { move(-move_speed); } if(Input.IsKeyPressed(Input.KEY.A)) { turn(turn_speed); } if(Input.IsKeyPressed(Input.KEY.D)) { turn(-turn_speed); } } void move(float speed) { node.WorldPosition += node.GetWorldDirection(MathLib.AXIS.Y)*speed*Game.IFps; } void turn(float speed) { node.Rotate(0,0,speed*Game.IFps); } } Link to comment
david.cambre Posted August 25, 2020 Share Posted August 25, 2020 Hi, I have used setVelocityTransform to keep physics working on physics bodys. 1 Link to comment
AttackGorilla Posted August 26, 2020 Author Share Posted August 26, 2020 9 hours ago, david.cambre said: Hi, I have used setVelocityTransform to keep physics working on physics bodys. Thank you. I will give that a try. Is there an example or code snippet anywhere to ease me into utilizing this? Link to comment
david.cambre Posted August 27, 2020 Share Posted August 27, 2020 @AttackGorilla First lets use raycast to get position and normal // initializing points of the ray from player's position in the direction pointed by the mouse cursor vec3 p0 = player.WorldPosition; vec3 p1 = p0 + new vec3(player.GetDirectionFromScreen(mouse.x,mouse.y))*Range; //creating a WorldIntersection object to store the information about the intersection WorldIntersectionNormal intersectionNormal = new WorldIntersectionNormal(); // casting a ray from p0 to p1 to find the first intersected object IntersectObject = World.GetIntersection(p0, p1, 1, intersectionNormal); target = intersection_normal.Point; target_normal = intersection_normal.Normal; Secondly align to private void set_interface_position() { if(pointer.has_target) { interface_node.Enabled = true; NodeDummy transform_manipulator = new NodeDummy(); transform_manipulator.SetDirection(pointer.target_normal, vec3.UP, MathLib.AXIS.NZ); // v3 needs upgraded code to work with dummy positions vec3 v3 = pointer.target_normal * 0.3f; transform_manipulator.Position = pointer.target + v3; interface_node.ObjectBody.SetVelocityTransform(transform_manipulator.Transform); } else { interface_node.Enabled = false; } } I know using Transform and MathLib it is cleaner then using a dummy node. That is for the next version of this code Link to comment
AttackGorilla Posted August 28, 2020 Author Share Posted August 28, 2020 Got it working. Thank you so much for the help. Ultimately used the code for the 3rd person shooter sample as reference. The rigid body velocity code in there worked great. Link to comment
Recommended Posts